Timur Mustafaev
Timur Mustafaev

Reputation: 4929

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:

enter image description here

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?

Upvotes: 2

Views: 3793

Answers (3)

crackity_jones
crackity_jones

Reputation: 1077

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;

Upvotes: 2

Filip Radelic
Filip Radelic

Reputation: 26683

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];

Upvotes: 2

jussi
jussi

Reputation: 2216

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.

Upvotes: 4

Related Questions