Reputation: 33
I am banging my head against a wall, thinking this should be simple, but I cannot figure it out.
I have an app, with multiple instances of the same Navigataion Controller class. Is it possible to add code to said Navigation Controller class (in this case UIBarButtonItems for the toolbar) so that anything I do in that class will show up anywhere within that navigation controller?
I have added the following code, yet nothing shows up on the toolbar:
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemSystemItemAdd target:self action:nil];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *toolbarItems = [NSArray arrayWithObjects:flexibleSpace, add, flexibleSpace];
[toolBar setItems:toolbarItems animated:NO];
Upvotes: 2
Views: 61
Reputation: 33
What I ended up doing to fix it, is to build all of the items to go in the tool bar and then call from the NavigationController class:
self.topViewController.toolbarItems = [NSArray arrayWithObjects: obj1, obj2, obj3, nil];
Upvotes: 0
Reputation: 16290
In your call to -arrayWithObjects:
you have forgotten to terminate the list with nil
.
NSArray *toolbarItems = [NSArray arrayWithObjects:flexibleSpace, add, flexibleSpace, nil];
Upvotes: 1