UIToolbar buttons disappear when a new view is clicked on the navigation stack

I have an iPhone app based on a UINavigationController with a UIToolbar at the bottom with various buttons in it that I created through Interface Builder. When I use [navigationController pushViewController:animated:] , my new view slides into place as expected, but then all the buttons disappear from the toolbar - the toolbar itself remains visible, it is just completely empty.

How to make buttons stay in place?

Here's a bit where I respond to the user by clicking one of the toolbar buttons, which then shows a new view:

 - (IBAction)clickSettings:(id)sender { NSLog(@"Clicked on 'Settings' button"); SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"Settings" bundle:nil]; [navigationController pushViewController:settingsViewController animated:YES]; } 
+4
source share
2 answers

Toolbar buttons are a property of this view; when you click a new view on the navigation bar stack, the toolbar buttons of the new view will be put in place.

The toolbar itself "belongs" to the navigation controller; toolbar visibility is controlled using the UINavigationControllerHidden toolbar, i.e.

 self.navigationController.toolbarHidden = YES; 
+4
source

To actually hold the toolbar from one view to the next, you can copy the toolbarItems property from one UIView to another.

+2
source

Source: https://habr.com/ru/post/1337592/


All Articles