首页 > 代码库 > NSUserDefaults存取失败

NSUserDefaults存取失败

解决办法:

1.存储NSUserDefaults时,强制NSUserDefault存入沙盒

[[NSUserDefaults standardUserDefaults] setObject:sAccount forKey:kSAVE_LOGIN_ACCOUNT];
[[NSUserDefaults standardUserDefaults] setObject:sPassword forKey:kSAVE_LOGIN_PASSWORD];
[[NSUserDefaults standardUserDefaults] synchronize];

 

2.取出NSUserDefaults时,不要在ViewDidLoad中取,在ViewWillAppear中取出来使用

 

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #6122ae } span.s1 { }</style>

NSUserDefaults存取失败