I have a navigation toolbar in which I am adding toolbar items programatically, as below. The toolbar displays properly, and the toolbar style is set to black opaque. but the button on the toolbar does not display. Why?
//Set up the toolbar
[[[self navigationController] toolbar] setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *myButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(handleMyButton)];
NSArray *myItems = [NSArray arrayWithObjects: myButtonItem,nil];
[[self navigationController] setToolbarItems:myItems animated:NO];
[myButtonItem release];
UINavigationController
fetches the buttons that should be used for the navigation bar and the tool bar from the current visible view controller. This means that you add the buttons you want to have to the view controller, not the navigation controller. So it should work just fine if you do:
[self setToolbarItems:myItems animated:NO];
Compare that with how the add button is added to the navigation bar in the default template for a Navigation Based Application with Core Data:
self.navigationItem.rightBarButtonItem = addButton;
This means that when you push a new view controller the buttons in the tool bar will disappear and then appear again when you pop back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With