我想在用户退出应用程序时保存用户所在的当前选项卡,这样我就可以在用户重新进入应用程序时加载应用程序并突出显示该选项卡。
我想我在我的应用程序委托(delegate)中使用以下方法来保存当前选项卡
- (void)applicationWillTerminate:(UIApplication *)application
但我如何获得对当前选项卡的访问权限 - 重新加载它的最佳方式是什么?
最佳答案
在 applicationWillTerminate 中,将 tabbarcontroller 的 selectedIndex 保存为默认值。
[[NSUserDefaults standardUserDefaults] setInteger:[tabBarController selectedIndex] forKey:@"tabBarIndex"];
然后在启动时,从 NSDefaults 中读取索引,然后设置选项卡。
setIndex = [[NSUserDefaults standardUserDefaults] objectForKey:@"tabBarIndex"];
[[NSUserDefaults standardUserDefaults] synchronize];
setIndex 是一个 NSUInteger。然后像这样在您的 viewDidLoad 中设置 TabBarController:
[tabBarController selectedIndex:setIndex];
这是靠内存,所以你需要尝试一下,但这是一般的做法。
干杯,乔丹
关于ios - 如何在用户退出时保存当前选项卡栏项目并在重新启动时重新加载到该项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/692979/