UINavigationController add Right button
I know this question was asked many times, but I didn't find my situation: I have 1 UINavigationController in Main window. Main Window сontains also UITableView. When i select row, NavigationController pushes another UIViewController with nib. This UIViewController doesn't have Navigation controller, it开发者_运维百科 contains only UITableView inside.
Here is screenshot of this UIViewController:
This is not Main Window. Main Window contains UINavigationController with UITableView.
And here is question:
How to add UIBarButtonItem into NavigationItem when i'm in pushed UIViewController?
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveItem)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];
add this in your viewDidLoad method to create a Save Button.
Inside that detail view controller's .m file, create an UIBarButton instance and set it as self.navigationItem.rightBarButtonItem. You can do it in init method.
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"title"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(someMethod)];
self.navigationItem.rightBarButtonItem = barButton;
[barButton release];
The view controller still contains a UINavigationItem and it is usable since you were pushed into a UINavigationController.
So you can simply do the following In your viewDidLoad method
self.navigationItem.rightBarButtonItem = yourBarButtonItem;
精彩评论