Three20's URL-based navigation + tab bar example?

佐手、 提交于 2019-12-10 09:23:52

问题


I just found out how easy it is (or at least is supposed to be) to do state persistence with Three20 library. However, I am unable to figure out how to use the URL mapper with a tab bar (UITabBarController).

The situation is this:

  1. I have four tabs and different controllers for them: FirstViewController, SecondViewController, ThirdViewController and FourthViewController.
  2. I want to map those to tt://tabs/first, ..., tt://tabs/fourth respectively, and have them saved somewhere when application closes so that the previously viewed tab is automatically opened when the application starts again.

My code so far:

// 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 opened tab, and if there's none - fallback to FirstViewController?


回答1:


So, I just found out about TTNavigatorDemo ;-)

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



来源:https://stackoverflow.com/questions/2322406/three20s-url-based-navigation-tab-bar-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!