我正在使用 iOS 6 Preservation and Restoration(没有 Storyboard),它与导航控制器一起工作正常,但是如果我在主窗口上手动添加 Tabbar 控制器,我没有得到选中的选项卡。
例如。
ListViewController *list = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];
SettingViewController *setting = [[SettingViewController alloc] initWithNibName:@"SettingViewController" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:list];
navigation.restorationIdentifier = @"NavigationControllerID";
self.tabbar = [[UITabBarController alloc] init];
self.tabbar.restorationIdentifier = @"TabbarControllerID";
self.tabbar.viewControllers = @[navigation,setting];
[[_tabbar.tabBar.items objectAtIndex:0] setTitle:NSLocalizedString(@"List", @"comment")];
[[_tabbar.tabBar.items objectAtIndex:1] setTitle:NSLocalizedString(@"Setting", @"comment")];
self.window.rootViewController = self.tabbar;
[self.window makeKeyAndVisible];
在他的情况下,我每次都会选择第一个选项卡。我已经植入
+ (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
用于设置视图控制器。