UITabBarController Auto-Save Order

Shaun, Feb 16

If you allow your UITabBarController to be customized, you'll notice a huge oversight in the UITabBarController class: there's no way to save the order after they're done customizing.

On OSX, Apple handles issues like these with an 'autosave name' that handles everything for you automatically, it seems to be missing from the iPhone SDK, so you have to figure it out on your own.

We decided to handle the autosaving/loading in the UIApplication delegate, here's what we came up with:


This works by checking the class name of each controller, and reordering it based on that.  This won't work if you use the same class for multiple UITabBarItems,  but we took the assumption that you'll be using a different class for each item. This does however, account for using multiple UINavigationController's by checking the topViewController class instead of storing UINavigationController over and over again.

If you do actually use the same class name in UITabBarItems, you can switch the code above to check for the controller's tabBarItem tag value instead of the class name.  We choose to use the class name so there was no extra work involved in having to set the tag value in IB.

blog comments powered by Disqus