应用程序终止后恢复segmenedControl的选定索引
所以我在界面中有这个分段控件,我使用用户默认值将选定的段存储在应用程序视图控制器的 applicationDidEnterBackground
中,并将其恢复到 - (void)applicationWillEnterForeground {
NSNumber *indexNumber;
if (indexNumber = [[NSUserDefaults standardUserDefaults] objectForKey:@"selectedIndex"]) {
<代码> NSInteger selectedIndex = [索引编号整数值]; self.segmentedControl.selectedSegmentIndex = selectedIndex; 但是
当我启动应用程序,选择一个段然后终止该应用程序时,我收到此错误。 程序收到信号:重新启动时“SIGKILL”。
任何帮助将不胜感激
so i have this segmented control in the interface i am using user defaults to store the selected segment in applications view controller's applicationDidEnterBackground
and restoring it in- (void)applicationWillEnterForeground {
NSNumber *indexNumber;
if (indexNumber = [[NSUserDefaults standardUserDefaults] objectForKey:@"selectedIndex"]) {
NSInteger selectedIndex = [indexNumber integerValue];
self.segmentedControl.selectedSegmentIndex = selectedIndex;
}
but when im launching the app, selecting a segment and then killing the application, i get this error.
Program received signal: “SIGKILL” on relaunch.
any help would be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有更多信息,很难说,但这可能是因为控制器和分段控件在 applicationWillEnterForeground 中不可用而引起的。 (它们还没有被实例化。)
您可能需要将更多内容添加到 viewController 的 viewDidLoad 中。
Hard to tell without more info, but likely this is caused because the controller and segmented control are not available in applicationWillEnterForeground. (They haven't been instantiated yet.)
You might need more this to the viewDidLoad of the viewController.