So I’m trying to add a UIToolbar to a UIViewController that is part of a UINavigation hierarchy and I was wondering what is the best way to do this. I know in iOS3 they enabled each viewcontroller that is part of a navigation hierarchy to have it’s own toolbar so I figure this is the best way to do it. However, the syntax of how I’m doing is bugging me, as I’m using three different types of syntax to add the toolbar as follows:
[[self navigationController] setToolbarHidden:NO];
[self setToolbarItems: myToolbarButtons];
[[[self navigationController] toolbar]setBarStyle:UIBarStyleBlack];
This works fine, and actually fixes a bad memory access from when I was adding the toolbar to the subview of the navigation view. But I don’t understand how I can do “self setToolbarItems” after I make the toolbar visible. Does it become a part of the viewcontroller then? Like I said, this works but is bugging me.
An UIVIewController has a property called UINavigationController. Each UINavigationController has a built-in toolbar of their own. So when you are calling,
you are actually enabling the toolbar of the navigationController property that comes with each UIViewController. And when you set the toolbar’s item and style with the following two lines:
you are actually setting the items of that UINavigationController’s built-in toolbar.
Hope this helps. Check out the UIViewController Class Reference for more information.