1

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!

user988739
  • 25
  • 1
  • 4

2 Answers2

0

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
  • 32,532
  • 24
  • 103
  • 156
0

@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];
Mike Z
  • 4,121
  • 2
  • 31
  • 53