Search code examples
objective-cios7uitabbarcontroller

How to add extra tab bar button in tab bar controller without adding view controller on that button in iOS


How to add tab bar item in tab bar view controller without adding a view controller with that and tap on that button no view controller are open. Tap on that tap bar button a alert will show.


Solution

  • On view did load create a UITabBarItem programmatically with a special tag. In your tab controller set the delegate to your view controller. On the method

    - (void)tabBar:(UITabBar *)tabBar
     didSelectItem:(UITabBarItem *)item
    

    Check to see if the item has your custom tag and if so present an alert. If it requires a view to be linked with the UITabBarItem simply just set a view of another UITabBarItem for your alert view bar item.