作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下是我正在做的事情:
- (void) applicationWillTerminate: (UIApplication*) application {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:navigationController.viewControllers
forKey:@"diabetesstate"];
}
- (void) applicationDidFinishLaunching: (UIApplication*) application {
NSMutableArray *state = [[NSUserDefaults standardUserDefaults]
objectForKey:@"diabetesstate"];
if (state == nil) {
//Will initialize a new controller and put it as root view controller
}
else {
[navigationController setViewControllers:state animated:NO];
}
}
最佳答案
您似乎正在尝试将 UIViewController 添加到 userdefaults 中?我怀疑这会起作用。
我想你必须在其中放置一些标识符字符串或数字来告诉你当前显示的是哪个 View Controller ,并且当应用程序启动时基本上检查该值并相应地设置你的 View Controller 。
我需要为我的应用程序实现类似的东西。我有一个对象列表,当用户点击其中一个时,我将显示一个子对象。我的想法是,如果当前正在显示客户端对象,则存储客户端对象的 ID,否则为 NULL。当应用程序启动时,我将检查该值。如果它为 NULL,我将显示父对象的列表,否则我将显示具有 userdefaults 中 ID 的子对象。
关于iphone - 如何在 iPhone 中使用 NSUserDefaults 保存应用程序状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2995161/
我是一名优秀的程序员,十分优秀!