Example 320 URL-based navigation + tab bar?

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 ?

+4
source share
1 answer

So, I just found out about TTNavigatorDemo ; -)

Update: and also wrote a tutorial, see http://three20.pypt.lt/url-based-navigation-and-state-persistence

+6
source

Source: https://habr.com/ru/post/1302178/


All Articles