NSUserDefaults无法保存数据<转>

If you terminate your app by pressing the home button (in the Simulator or on the device), your User Defaults will get saved.

如果你按HOME键终止你的应用(真机或者模拟器上),你的值是会被保存的。

If you terminate your app by pressing "Stop" in Xcode (in the Simulator or on the device), your User Defaults might get saved, but there's a good chance they won't. NSUserDefaults persists any changes periodically, and if you terminate the process before they've been persisted, they'll be gone. You can force the save by calling:

[[NSUserDefaults standardUserDefaults] synchronize];
 
如果你在XCODE中,终止你的应用(在模拟器或者真机上),你的值或许不会被保存

你可以使用以下代码强制保存

[[NSUserDefaults standardUserDefaults] synchronize];
posted @ 2012-12-26 10:25  潁川君  阅读(202)  评论(0编辑  收藏  举报