开发者

NSUserDefaults - reload needed?

I use NSUserDefaults to store some stuff.

It works fine but only after i restart the app.

I use: [prefs synchronize]; I thought it would immediately save the data but instead preferences stay null.

If you have any idea or already de开发者_开发技巧al with it let me know. Thanks for any help.

Wallou


I finally managed to solve my issue. I was doing the same thing at two different places (old code forgotten somewhere). For information here is my code:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
// saving an NSString
[prefs setObject:identField.text forKey:@"mail"];
[prefs setObject:pwdField.text forKey:@"password"]; 
mail=[prefs objectForKey:@"mail"];
pwd=[prefs objectForKey:@"password"];

//This is to synch prefs
[prefs synchronize];
NSLog(@"pwd: %@, username:%@", mail, pwd);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜