0

My UINavigationController toolbar is blank and no items show up on it. Here is my code

self.navigationController.toolbarHidden = NO;

UIToolbar* toolbar = self.navigationController.toolbar;
NSMutableArray *items = [[NSMutableArray alloc] init];
[items addObject:[[UIBarButtonItem alloc] initWithTitle:@"Test"
                                                  style:UIBarButtonItemStylePlain
                                                 target:self
                                                 action:@selector(buttonPushed)]];
[toolbar setItems:items animated:YES];
user1802143
  • 14,662
  • 17
  • 46
  • 55

1 Answers1

1

That's not the proper way to setup the toolbar. UIViewController has a toolbarItems property. The nav controller will use that property to automatically populate its toolbar.

Your code should be:

self.navigationController.toolbarHidden = NO;

UIBarButtonItem *btnTest = [[UIBarButtonItem alloc] initWithTitle:@"Test"
                                              style:UIBarButtonItemStylePlain
                                             target:self
                                             action:@selector(buttonPushed)]];
self.toolbarItems = @[ btnTest ];
rmaddy
  • 314,917
  • 42
  • 532
  • 579