代码之家  ›  专栏  ›  技术社区  ›  Linas Valiukas

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

  •  4
  • Linas Valiukas  · 技术社区  · 16 年前

    我刚发现做起来有多容易 state persistence with Three20 library . 但是,我无法理解如何将URL映射器与选项卡一起使用。( UITabBarController )

    情况是这样的:

    1. 我有四个选项卡和不同的控制器: FirstViewController , SecondViewController ,请 ThirdViewController 和 FourthViewController .
    2. 我想把它们映射到 tt://tabs/first … tt://tabs/fourth 分别在应用程序关闭时将其保存到某个位置,以便在应用程序再次启动时自动打开以前查看的选项卡。

    我的代码到目前为止:

    // 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 打开上次打开的选项卡,如果没有-回退到 FirstView控制器 ?

    1 回复  |  直到 15 年前
        1
  •  6
  •   Linas Valiukas    16 年前

    所以,我才知道 TTNavigatorDemo ;-)

    更新: 还编写了教程,请参见 http://three20.pypt.lt/url-based-navigation-and-state-persistence