Navigationbar按钮不显示

有个UINavigationController,需要显示导航条按钮,代码如下:

UINavigationController *nav=[[UINavigationController alloc] init];
[self.view addSubview:nav.view];

UIImage *info_iphone=[UIImage imageNamed:@"button.png"];
UIButton *infobtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 48, 30)];
[infobtn setBackgroundImage:info_iphone forState:UIControlStateNormal];
[infobtn addTarget:self action:@selector(show_info:) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:infobtn];

如果上述的代码没有实现你要的效果。首先可能的原因就是当前控制器viewcontroller 不在导航控制器栈中。因为只有处于导航控制器栈中的控制器viewcontroller,你在设置了它的UIBarButtonItem后才会被显示出来。