Three20的基于URL的导航+标签栏示例?

时间:2010-02-23 22:57:02

标签: iphone three20

我刚刚发现state persistence with Three20 library是多么容易(或者至少应该是这样)。但是,我无法弄清楚如何将URL映射器与标签栏(UITabBarController)一起使用。

情况如下:

  1. 我有四个标签和不同的控制器:FirstViewControllerSecondViewControllerThirdViewControllerFourthViewController
  2. 我想分别将它们映射到tt://tabs/first,...,tt://tabs/fourth,并在应用程序关闭时将它们保存到某处,以便在应用程序再次启动时自动打开以前查看过的选项卡。 / LI>

    到目前为止我的代码:

    // 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];
    

    如何让TTNavigator打开上一个打开的标签,如果没有,则回退到FirstViewController

1 个答案:

答案 0 :(得分:6)

所以,我刚刚发现了TTNavigatorDemo; - )

更新:并撰写了一个教程,请参阅http://three20.pypt.lt/url-based-navigation-and-state-persistence