Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 没有故事板的Tabbar的保存和恢复_Iphone_Ios_Objective C_Ios6_Uikit State Preservation - Fatal编程技术网

Iphone 没有故事板的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中添加此方

我使用的是iOS 6保存和恢复(没有故事板),导航控制器可以正常工作,但如果我在主窗口上手动添加Tabbar控制器,我将无法获得选中的选项卡

例如

在这种情况下,我每次都会选择第一个选项卡。我已经

+ (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;