NavigationController + Toolbar
I am using a NavController, but i enabled the toolbar at the bottom. I also added UIBarButtonItem and o开发者_C百科n the IB, it shows. It basiclly looks like
- Navigation Controller
- Navigation Bar
- Toolbar
- Root View Controller
- Bar Button Item
- Navigation Item
So the Bar Button was added under Root View Controller, and i can see it in the IB where the Toolbar is, but when i run it, i can see the ToolBar, but not the Item which i called Item1 as its text!
Help
I've always found it a better idea to deal with a NavigationController's toolbar programmatically rather than in Interface Builder for just these reasons. The steps are
- Tell the navigation controller to show the toolbar
[navController setToolbarHidden:NO animated:YES]
. Sounds like you've done this step. - Create your UIBarButtonItems. Set your ViewController as the target of the bar buttons.
- Add your bar button items to an NSArray. Include buttonitems of type
UIBarButtonSystemItemFlexibleSpace
orUIBarButtonSystemItemFixedSpace
to arrange them where you want on the toolbar. Set the array to the toolbar'sitems
property. - Write the methods that handle what happens when the user taps these buttons.
- Make sure to release all these objects you've created as necessary.
No need to subclass anything. Feel free to ask more if this still doesn't work for you.
You need Navigation Controller->ToolBar controller->RootViewContoller if you want to add the Bar button Item at the RootView Controller level.
Otherwise you have subclass the Tool Bar View, set up the IBOutlet for the tool bar button on that and do setButtonText method for the Button text. Then you can include that subclass in your Root View controller and call the setButtonText method.
精彩评论