save and restore state of a tab bar controller

Posted by phunehehe on Stack Overflow See other posts from Stack Overflow or by phunehehe
Published on 2009-10-12T05:15:40Z Indexed on 2010/04/13 5:52 UTC
Read the original article Hit count: 342

I have an application that has a UITabBarController with two tabs, each having its own navigation controller. Now I want to store the state of the application when the user closes it, so that when the user relauches the application will show the same place as the last time before it was closed.
So, in applicationWillTerminate: I have

[NSKeyedArchiver archiveRootObject:tabBarController toFile:@"lastVisitedTab"];

Then, in applicationDidFinishLaunching: I have

UITabBarController *last= (UITabBarController *)[NSKeyedUnarchiver unarchiveObjectWithFile:@"lastVisitedTab"];
if (last)
    tabBarController = [last retain];

I also have an extension to UIImage to make it compliant to NSCoding. However, this doesn't work, as the state is not preserved. The first tab gets selected all the time, and no navigation is preserved either.
Can someone tell me what's wrong, or show me how to do it correctly?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about object-state