I am creating a toolbar in a Navigation Controller using the following code:
[self.navigationController setToolbarHidden:NO];
//Create a button
NSArray *toolbarItems = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithTitle:@"Help" style:UIBarButtonItemStyleBordered target:self action:@selector(helpButton:)]
,nil];
The only problem is that the toolbar is visible whenever there is a navigation controller(multiple other views). Is there a way to only restrict the toolbar to a single view?
Thanks
To quote the UINavigationController Class Reference:
The navigation toolbar is hidden by default but you can show it for your navigation interface by calling the
setToolbarHidden:animated:
method of your navigation controller object. If not all of your view controllers support toolbar items, your delegate object can call this method to toggle the visibility of the toolbar during subsequent push and pop operations.
So, set a delegate for your navigation controller. In your delegate's navigationController:willShowViewController:animated:
, do something like this:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
BOOL shouldShowToolbar = (viewController == theViewControllerThatNeedsAToolbar);
[navigationController setToolbarHidden:shouldShowToolbar animated:animated];
}
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