我刚发现做起来有多容易
state persistence with Three20 library
. 但是,我无法理解如何将URL映射器与选项卡一起使用。(
UITabBarController
)
情况是这样的:
-
我有四个选项卡和不同的控制器:
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
打开上次打开的选项卡,如果没有-回退到
FirstView控制器
?