I have an app with 5 tab bar items. I want to re-organize them, so I want to move the last position item to the 4th position.
Is there an easy way to do this?
Thanks!
I have an app with 5 tab bar items. I want to re-organize them, so I want to move the last position item to the 4th position.
Is there an easy way to do this?
Thanks!
Yes; you can ask your UITabController
for the viewControllers
array.
Once you have it, move the items as you want, and set it back using [yourUITabBarController setViewControllers:yourNewViewControllersArray]
.
@houbysoft's answer is correct, just a few more details:
You can call: @property(nonatomic, copy) NSArray *viewControllers
on your UITabBarController
Note that this will return you an NSArray
. In order to work with this you need to create a mutable copy. Then, you can use exchangeObjectAtIndex:withObjectAtIndex:
then pass this back in to setViewControllers:
The whole thing might look like this:
NSMutableArray *myArray = [[myTabBar viewControllers] mutableCopy];
[myArray exchangeObjectAtIndex:4 withObjectAtIndex:3];
[myTabBar setViewControllers:myArray];