NSUserDefaults无法正常保存 [英] NSUserDefaults not saving properly

查看:121
本文介绍了NSUserDefaults无法正常保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计我遇到NSUserDefaults的问题,我不太明白发生了什么

Hey Guys I'm having issues with NSUserDefaults and I don't quite understand what's going on

我的应用程序有5个级别,每个级别完全相同使用NSUserDefaults(检索级别默认值,在用户播放级别时更改值,然后在级别结束时设置默认值和同步)前4个级别...工作顺利但最后一级不保存价值。该应用程序不会崩溃,最后一个级别不是最后发生的事情,我甚至在应用程序终止时同步默认值。在NSUserDefaults上是否有最大尺寸,或者有什么人都可以想到我没有,我会发布下面的代码,但就像我说前四个级别完美运行

My App has 5 levels and each level does the exact same thing with NSUserDefaults (Retrieves the levels defaults, changes the value as the user plays the level and then sets the defaults and syncronizes at the end of the level) the first 4 levels...work without a hitch but the last level doesn't save the values. The app doesn't crash and the last level isn't the very last thing that happens, And I even have the defaults synchronized when the application terminates. Is there a max size on the NSUserDefaults or is there anything anyone can think of that I haven't, I'll post the code below but like I said the first four levels work perfectly

//header
NSUserDefaults *userData;


@property(nonatomic,retain) NSUserDefaults *userData;


//class file
//Sets the boolean variables for the class to use
userData = [NSUserDefaults standardUserDefaults];
boolOne = [userData boolForKey:@"LevelFiveBoolOne"];
boolTwo = [userData boolForKey:@"LevelFiveBoolTwo"];
boolThree = [userData boolForKey:@"LevelFiveBoolThree"];
boolFour = [userData boolForKey:@"LevelFiveBoolFour"];
boolFive = [userData boolForKey:@"LevelFiveBoolFive"];
boolSix = [userData boolForKey:@"LevelFiveBoolSix"];
boolSeven = [userData boolForKey:@"LevelFiveBoolSeven"];

//End Of Level
[userData setBool:boolOne forKey:@"LevelFiveBoolOne"];
[userData setBool:boolTwo forKey:@"LevelFiveBoolTwo"];
[userData setBool:boolThree forKey:@"LevelFiveBoolThree"];
[userData setBool:boolFour forKey:@"LevelFiveBoolFour"];
[userData setBool:boolFive forKey:@"LevelFiveBoolFive"];
[userData setBool:boolSix forKey:@"LevelFiveBoolSix"];
[userData setBool:boolSeven forKey:@"LevelFiveBoolSeven"];
[userData synchronize];

当我切换到使用这些默认值的视图时,它们的值是正确的但是当我终止应用程序时并重新启动它,这些值不会保存,每个其他级别执行完全相同的过程,这是唯一不起作用的级别。

When when I switch to the view that uses these defaults they values are correct but when I terminate the application and restart it, these values aren't saved, every other level does the exact same process this is the only level that doesn't work.

我盯着看这已经有一段时间了,我希望那里有人遇到同样的问题,可以给我一些他们如何解决它的见解。

I've stared at this for quite awhile and I'm hoping someone out there has run into the same problem and can give me some insight on how they resolved it.

先谢谢你b $ b BWC

Thank you in Advance BWC

推荐答案

NSUserDefaults可能无法保存,具体取决于流程的终止方式。

NSUserDefaults might not have a chance to save depending on how the process is terminated.

这个答案有更多信息:为什么NSUserDefaults没有保存我的值?

This answer has more info: Why is NSUserDefaults not saving my values?

这篇关于NSUserDefaults无法正常保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆