2011-09-02 46 views
2

我知道这个问题被问了很多次,但我没有找到我的情况: 我在主窗口中有1个UINavigationController。主窗口也包含UITableView。当我选择行时,NavigationController用nib推入另一个UIViewController。这个UIViewController没有导航控制器,它只包含里面的UITableView。UINavigationController add right button

下面是该UIViewController中的截图:

enter image description here

这不是主窗口。主窗口包含带有UITableView的UINavigationController。

这里是问题:

如何的UIBarButtonItem加入到NavigationItem当我在推的UIViewController我?

回答

2

在该详细视图控制器的.m文件中,创建一个UIBarButton实例并将其设置为self.navigationItem.rightBarButtonItem。你可以在init方法中做到这一点。

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"title" 
                   style:UIBarButtonItemStyleBordered 
                  target:self 
                  action:@selector(someMethod)]; 
self.navigationItem.rightBarButtonItem = barButton; 
[barButton release]; 
+0

的工作,谢谢:) –

4
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveItem)]; 

self.navigationItem.rightBarButtonItem = saveButton; 
[saveButton release]; 

将此添加到您的viewDidLoad方法中以创建保存按钮。

2

视图控制器还包含一个UINavigationItem,它是可用的,因为你推到一个UINavigationController。

因此,你可以简单地做下面的在你viewDidLoad方法

self.navigationItem.rightBarButtonItem = yourBarButtonItem;