Wednesday, October 31, 2012

iOS Removing a Tab from a UITabController

If you are like me and have been trying to remove a tab from a UITabController, have scoured the web and have found posts suggesting copying the UIBarItems to an array, removing one than setting the bar items again, you will run into the following exception :

'Directly modifying a tab bar managed by a tab bar controller is not allowed.'

Instead, use the UITabBarController's viewControllers property and your tab will be properly removed without throwing an exception

      // Remove the first tab from a tab bar controlled by a UITabController  
      NSMutableArray * vc = [NSMutableArray   
                arrayWithArray:[self.tabBarController viewControllers]];  
      [vc removeObjectAtIndex:0];  
      [self.tabBarController setViewControllers:vc];  


No comments:

Post a Comment