I am having problems finding any other information than the docs for how to save the tab order for my UITabBarController, so that the user’s customization is saved for next app launch. I have searched online, but have been unable to find any blog posts or articles that goes through the proper code for doing this.
I realize I have to use the delegate methods for the UITabBarController (didEndCustomizingViewControllers:) but I am not sure how I best approach persistance in terms of saving the state of the order the user wants the tabs in.
Can someone post some code, point me in the right direction or perhaps you have a link for something saved? 🙂
Thanks
As far as you’ve asked for some sample code I will simply post here how I dealt with the same task in my app.
Quick intro: I was using a NIB file for storing initial
UITabBarControllerstate and to differ my tabs one from another I simply defined tag variables forUITabBarItemobjects assigned to eachUIViewControllerstuffed in myUITabBarController. To be able to accurately track last selected tab (including the ‘More’ one) I’ve implemented following methods forUITabBarControllerDelegateof myUITabBarControllerandUINavigationControllerDelegateof its moreNavigationController. Here they are:And here’s the code for saving the tabs order:
As you can see I’ve been storing the order of tabs’ indexes in an array in
NSUserDefaults.On app’s launch in
applicationDidFinishLaunching:method I reordered theUIViewControllersusing following code:It’s quite tricky and may seem strange, but don’t forget that my
UITabBarControllerwas fully created in a nib file. If you construct it programmatically you may simply do the same but following the saved order.P.S.: and don’t forget to synchronize
NSUserDefaultswhen your app terminates.I hope this will help. If something is not clear please do comment and ask.