NSUserDefaults无法保存数据

需要 synchronize一下


参考资料:http://stackoverflow.com/questions/2622754/why-is-nsuserdefaults-not-saving-my-values/2622940#2622940


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

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];


posted on 2011-10-29 16:54  大宝pku  阅读(560)  评论(0编辑  收藏  举报

导航