gpt4 book ai didi

iphone - 如何在 iPhone 中使用 NSUserDefaults 保存应用程序状态?

转载 作者:行者123 更新时间:2023-12-03 20:10:56 25 4
gpt4 key购买 nike

以下是我正在做的事情:

- (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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com