【发布时间】:2023-03-31 16:05:01
【问题描述】:
我正在使用 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
用于设置视图控制器。
【问题讨论】:
标签: iphone ios objective-c ios6 uikit-state-preservation