Iphone 没有故事板的Tabbar的保存和恢复
我使用的是iOS 6保存和恢复(没有故事板),导航控制器可以正常工作,但如果我在主窗口上手动添加Tabbar控制器,我将无法获得选中的选项卡 例如 在这种情况下,我每次都会选择第一个选项卡。我已经Iphone 没有故事板的Tabbar的保存和恢复,iphone,ios,objective-c,ios6,uikit-state-preservation,Iphone,Ios,Objective C,Ios6,Uikit State Preservation,我使用的是iOS 6保存和恢复(没有故事板),导航控制器可以正常工作,但如果我在主窗口上手动添加Tabbar控制器,我将无法获得选中的选项卡 例如 在这种情况下,我每次都会选择第一个选项卡。我已经 + (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder 用于设置视图控制器 通过在Appdelegate中添加此方
+ (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
用于设置视图控制器 通过在Appdelegate中添加此方法 NSString*const AppDelegateRootVCKey=@“AppDelegateRootVCKey” } }
+ (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
- (void)application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder {
//Adding last tabbar selected index
[coder encodeObject:[NSString stringWithFormat:@"%d",self.tabbar.selectedIndex]forKey:AppDelegateRootVCKey];
- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder {
//Setting Last tabbar selected index
NSString *selectedStr = [coder decodeObjectForKey:AppDelegateRootVCKey];
self.tabbar.selectedIndex = [selectedStr intValue];
return YES;