应用程序终止后恢复segmenedControl的选定索引

所以我在界面中有这个分段控件我使用用户默认值将选定的段存储在应用程序视图控制器的
applicationDidEnterBackground
中并将其恢复
- (void)applicationWillEnterForeground {
NSNumber *indexNumber;
if (indexNumber = [[NSUserDefaults standardUserDefaults] objectForKey:@"selectedIndex"]) {
NSInteger selectedIndex = [indexNumber integerValue];
self.segmentedControl.selectedSegmentIndex = selectedIndex;
    }
但是当我启动应用程序,选择一个段然后杀死应用程序时,我收到此错误。 程序收到信号:重新启动时“SIGKILL”。 任何帮助,将不胜感激     
已邀请:
没有更多信息很难说,但可能是因为控制器和分段控件在applicationWillEnterForeground中不可用。 (它们尚未实例化。) 您可能需要更多这个到viewController的viewDidLoad。     

要回复问题请先登录注册