我在保留申请状态方面遇到了问题。 我的应用程序基于故事板,这是它的方式。 首先我有一个导航控制器,然后是一个登录屏幕。当用户登录时,我将其推送到左侧有桌面视图的控制器,使用UITabbar项目,这主要是一个自定义标签栏。单击每个按钮,我将该容器视图添加到self。应用程序状态保留到此为止,但每当我进一步推动时,它都不会保留和恢复状态。在自定义选项卡栏上,我甚至对子视图控制器进行编码和解码,并在状态恢复时相应地添加。但是当我进一步导航时却没有。此外,我看到了一个奇怪的行为,如果我最初点击第一个标签项并在导航中进一步移动,它会进一步保留和恢复状态。 还有一件事,当我通过点击停止和播放按钮在模拟器上运行应用程序时,它会显示保留视图几秒钟并返回自定义选项卡栏。 任何帮助将不胜感激。
我的标签栏代码是
// encodeRestorableStateWithCoder is called when the app is suspended to the background
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
NSLog(@"ParentViewController: encodeRestorableStateWithCoder");
[coder encodeObject:theNavigationController forKey:@"RootNav"];
[coder encodeObject:ssTodayNaVController forKey:@"TodaysCallNavEncode"];
// remember our children view controllers
[coder encodeObject:self.ssDasboardVC forKey:@"DashboardChild"];
[coder encodeObject:self.ssMessageVC forKey:@"MessageChild"];
[coder encodeObject:self.ssSearchCustomerVC forKey:SEARCH_CUSTOMER_SCENE];
[coder encodeObject:self.ssTodaysCallVC forKey:TODAYS_SCENE];
// remember the segmented control state
[coder encodeInteger:self.tabBar.mSelectedIndex forKey:@"selectedIndex"];
[super encodeRestorableStateWithCoder:coder];
}
// decodeRestorableStateWithCoder is called when the app is re-launched
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder
{
NSLog(@"ParentViewController: decodeRestorableStateWithCoder");
theNavigationController=[coder decodeObjectForKey:@"RootNav"];
ssTodayNaVController=[coder decodeObjectForKey:@"TodaysCallNavEncode"];
self.tabBar.mSelectedIndex = [coder decodeIntegerForKey:@"selectedIndex"];
[[NSNotificationCenter defaultCenter]postNotificationName:TABBUTTON_NOTIFICATION object:[NSNumber numberWithInteger:self.tabBar.mSelectedIndex]];
[self.tabBar reloadData];
[super decodeRestorableStateWithCoder:coder];
}
如果我用这种方法打印保存的控制器,它会打印但不保存
- (UIViewController *)application:(UIApplication *)application
viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents
coder:(NSCoder *)coder {
// return various navigation controllers here.
// actual view controlers will each be returned in their own classes
SCLogNotice(@"Saved Controllers are %@",identifierComponents);
return nil;
}
干杯