Iphone xcode4.2中导航栏中的多个右栏按钮

Iphone xcode4.2中导航栏中的多个右栏按钮,iphone,ios5,uinavigationbar,rightbarbuttonitem,Iphone,Ios5,Uinavigationbar,Rightbarbuttonitem,我想在导航栏右侧创建三个按钮。我正在使用故事板创建UIView控制器。 详细地说,ViewController使用故事板嵌入了一个导航栏,然后通过编程创建了三个UIBarButtonim,然后将它们添加到数组中,然后将其分配给navigationitem。这很好 UIBarButtonItem *Button1 = [[UIBarButtonItem alloc]initWithTitle:@"Button1" style:UIBarButtonItemStylePlain

我想在导航栏右侧创建三个按钮。我正在使用故事板创建UIView控制器。 详细地说,ViewController使用故事板嵌入了一个导航栏,然后通过编程创建了三个UIBarButtonim,然后将它们添加到数组中,然后将其分配给navigationitem。这很好

UIBarButtonItem *Button1 = [[UIBarButtonItem alloc]initWithTitle:@"Button1" style:UIBarButtonItemStylePlain
                                                           target:self action:@selector(Button1Clicked:)] ;

UIBarButtonItem *Button2 = [[UIBarButtonItem alloc] initWithTitle:@"Button2" style:UIBarButtonItemStylePlain
                                                             target:self action:@selector(Button2Clicked:)] ;

UIBarButtonItem *Button3 = [[UIBarButtonItem alloc] initWithTitle:@"Button3" style:UIBarButtonItemStylePlain
                                                              target:self action:@selector(Button3Clicked::)] ;

self.navigationItem.rightBarButtonItems =
[NSArray arrayWithObjects:Button1,Button2,Button3, nil];
我有另一个viewcontroller这是一个ModalViewController。我正在使用序列图像板创建视图控制器,并添加导航栏而不是导航控制器。然后使用相同的方法将按钮添加到导航栏,但未显示任何按钮。
请大家知道如何解决这个问题。

如果您的viewController位于
UINavigationController
中,请添加
UINavigationBar
而不是
UINavigationItem
,您只需使用

self.navigationItem ...
在我看来,这很好用。但是,如果在
UINavController
中您的viewController(本例中为您的模式)不是not,则您必须通过以下方式访问
UINavigationItem

someNavigationBar.topItem ...
因此,如果您将
IBOutlet
设置到导航栏,您的代码应该如下所示:

UIBarButtonItem *Button1 = ...
UIBarButtonItem *Button2 = ...
UIBarButtonItem *Button3 = ...

yourNavigationBar.topItem.rightBarButtonItems = [NSArray arrayWithObjects:Button1, Button2, Button3, nil];

请提供一些信息或代码,您卡在哪里?谢谢您的回复。当单击一个按钮时,会显示一个新的车辆控制器。我想要一个导航栏,该视图控制器右侧有三个按钮。上面的代码对此不起作用。缺少什么?