title: save and restore state of a tab bar controller
body: <p>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.<br>
  So, in applicationWillTerminate: I have</p>
  
  <pre><code>[NSKeyedArchiver archiveRootObject:tabBarController toFile:@"lastVisitedTab"];
  </code></pre>
  
  <p>Then, in applicationDidFinishLaunching: I have</p>
  
  <pre><code>UITabBarController *last= (UITabBarController *)[NSKeyedUnarchiver unarchiveObjectWithFile:@"lastVisitedTab"];
  if (last)
      tabBarController = [last retain];
  </code></pre>
  
  <p>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.<br>
  Can someone tell me what's wrong, or show me how to do it correctly?</p>