Reputation: 315
I want to add buttons to my navigation bar through code, but they are not appearing for me. I think it might have to do with my navigation bar being inside a UIView.
My code in viewDidLoad
:
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
self.navigationItem.rightBarButtonItem = addButton;
Interface builder:
Any help would be greatly appreciated!
Upvotes: 1
Views: 88
Reputation: 57060
You shouldn't add a navigation bar directly in your view hierarchy. Rather, add a navigation controller, have your view controller as the root controller of the navigation controller, and set the navigation controller as the initial controller of the storyboard (or as the destination controller of segues, etc.).
Upvotes: 1