【发布时间】:2010-02-23 22:57:02
【问题描述】:
我刚刚发现(或至少应该)做state persistence with Three20 library 是多么容易。但是,我无法弄清楚如何使用带有标签栏 (UITabBarController) 的 URL 映射器。
情况是这样的:
- 我有四个选项卡和不同的控制器:
FirstViewController、SecondViewController、ThirdViewController和FourthViewController。 - 我想将它们分别映射到
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 打开最后打开的选项卡,如果没有 - 回退到 FirstViewController?
【问题讨论】: