silverkid
silverkid

Reputation: 9563

increasing and decreasing the number of tabs in tabBarcontroller ios

i have created tabs using tabBarcontroller.

oringnally my code was written for the number of tabs to be fixed to 5.

now i need to change the number of tabs to be unfixed and can vary from lets say 1 to 5.

the decision lies with the user who can change the values in a server.

each time i load the view in tab the synchronisation with server data happens.

so at this point the user can decide to go from 5 to 3 tabs. and on next tab press from 3 to 4

how do i increase and decrease the number of tabs on tab press

Upvotes: 0

Views: 92

Answers (2)

Unheilig
Unheilig

Reputation: 16292

For starters you could manage the UITabbarController tab by accessing it like so:

NSMutableArray *myViewControllersInTabBar = [NSMutableArray arrayWithArray:[self.tabBarController viewControllers]];

To remove:

[myViewControllersInTabBar removeObjectAtIndex:<INDEX_OF_CONTROLLER_YOU_WISH_TO_REMOVE];

To add:

[myViewControllersInTabBar insertObject:<CONTROLLER_TO_ADD> atIndex:<INDEX_NUMBER>];

Then:

[self.tabBarController setViewControllers:myViewControllersInTabBar];

To get notification when a tab is selected, conform to UITabBarControllerDelegate and implement the methods.

One of these being:

– tabBarController:didSelectViewController:

Here is a to a list of UITabBarControllerDelegate's delegate methods:

UITabBarControllerDelegate Protocol

Hope this helps.

Upvotes: 1

Kevin Enax
Kevin Enax

Reputation: 176

[UITabBar setItems:(NSArray *)items animated:(BOOL)animated]

You'll have to manage the array manually, and use the UITabBarControllerDelegate methods if you want to do it on selection of a tab.

Upvotes: 1

Related Questions