In the storyboard I created a DetailViewController with a UIToolbar at bottom, and one button.
There are special times where I want to present this view controller with an alternative set of buttons.
When I want to present the view controller modally with the extra buttons, I have to initialize the view controller programmatically from the storyboard like so:
DetailViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
[controller newButtons:YES];
[self presentViewController:controller animated:YES completion:nil];
In the DetailViewController.m file I have the method which is called above:
-(void) newButtons: (BOOL) isNew
{
if (isNew) {
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@ selector( save:)];
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@ selector( cancel:)];
NSArray *buttonArr = [[NSArray alloc] initWithObjects:doneItem, cancelItem, nil];
[self.toolbar setItems:buttonArr animated:YES];
}
}
I have created an outlet from the storyboard to DetailViewController.m file by clicking an dragging to the top of the file which made:
@property (weak, nonatomic) IBOutlet UIToolbar *toolbar;
These are all the steps but when I click the button to present the view controller, it just shows the view controller with the original button from the Storyboard, not the 2 new ones I programmatically added.
How come it is not showing the new buttons. I logged a test statement from the newButtons method and it is calling it for sure. Just not adding the buttons???
UPDATE:
I added breakpoint to [self.toolbar setItems:animated] and it did not call the statement, even though the method was called. self.toolbar is null.
How come it is null? I cntrl-click dragged to the top of DetailViewController.m and added it. I tried with both strong, and weak properties.