Problem adding tab bar items to UITabBar

Aqueel picture Aqueel · May 31, 2011 · Viewed 14.3k times · Source

I have a tab bar based application in which I am trying to add tab bar items to the tab bar dynamically using setItems method of the UITabBar.

Here is the code:

[self.tabBarController.tabBar setItems:self.level1TabBarItems animated:YES];

Where self.level1TabBarItems is an NSMutableArray with 4 UITabBarItems in it. When I run this code, I get an exception from the compiler.

NSInternalInconsistencyException, reason:Directly modifying a tab bar managed by a tab bar controller is not allowed.

I have tried deleting the UITabBarViewController and adding it again but it did not work.

Answer

Deepak Danduprolu picture Deepak Danduprolu · May 31, 2011

The documentation clearly states that you shouldn't modify the tab bar directly. Use setViewControllers:animated: instead.