I just figured out how easy (or at least it should be) to save state using the Three20 library . However, I cannot figure out how to use a URL map with a tab bar ( UITabBarController ).
The situation is as follows:
- I have four tabs and different controllers for them:
FirstViewController , SecondViewController , ThirdViewController and FourthViewController . - I want to bind them to
tt://tabs/first , ..., tt://tabs/fourth respectively, and save them somewhere when the application closes, so the previously viewed tab automatically opens when the application starts again.
My code is:
// Init the tab bar tabBarController = [[UITabBarController alloc] init]; [tabBarController setDelegate:self]; // Init the navigator TTNavigator *navigator = [TTNavigator navigator]; [navigator setWindow:window]; [navigator setPersistenceMode:TTNavigatorPersistenceModeAll]; // Begin mapping TTURLMap *map = [navigator URLMap]; [map from:@"tt://tabs" toViewController:[UIViewController class]]; [map from:@"tt://tabs/first" toViewController:[FirstViewController class]]; [map from:@"tt://tabs/second" toViewController:[SecondViewController class]]; [map from:@"tt://tabs/third" toViewController:[ThirdViewController class]]; [map from:@"tt://tabs/fourth" toViewController:[FourthViewController class]]; // Try restoring if (! [navigator restoreViewControllers]) { // Open default TTURLAction *defaultAction = [[TTURLAction alloc] initWithURLPath:@"tt://tabs/default"]; [defaultAction setParentURLPath:@"tt://tabs"]; [navigator openURLAction:defaultAction]; } // Put view controllers to tab bar [tabBarController setViewControllers:[NSArray arrayWithObjects: [[FirstViewController alloc] init], [[SecondViewController alloc] init], [[ThirdViewController alloc] init], [[FourthViewController alloc] init], nil]]; [window addSubview:tabBarController.view]; [window makeKeyAndVisible];
How do I get TTNavigator to open the last open tab, and if not, FirstViewController from FirstViewController ?
Linas source share