I am wondering if there is a way to add an additional UITabBarItem
to my exisiting UITabBarController
. It doesn't need to be in runtime.
All I want to do is when hitting this button I want to presentModalViewController:
over my actually visible ViewController, which should either be the TabBarController or its controllers.
Hopefully this is clear enough, if not, feel free to ask.
As a result of my research you cannot add a UITabBarItem to a UITabBar that is managed by a UITabBarController.
Since you maybe have added your UITabBarItem by adding a list of view controller, this is also the way of your choice to add further custom UITabBarItems, as i will show now:
Pre-Conditions: As i mentioned before, you maybe have added your UITabBarItems by adding a list of view controller:
Adding custom UITabBarItems: Now since you know how to add UITabBarItems through adding view controller, you can also use the same way to add custom UITabBarItems:
Modify the line above:
All fine, now you have your custom button in your TabBar.
What about handling events of this custom UITabBarItem?
Its easy, look:
Add the UITabBarControllerDelegate to your AppDelegate class (or the class which is holding the tabbarController).
Fit the protocol definition by adding this function:
Now you have all you need to create and handle custom UITabBarItems. Hope this helps. Have fun....
Access the tabBar - property of your UITabBarController (reference), grab the elements array with the
items
- property (reference), add a new UITabBarItem to this array and use the tabBar'ssetItems:animated:
- method to update your tab bar. Add an action to this tab bar to display the modal view controller.