开发者

Cannot set NSUserDefault ToggleSwitch Value

I have a form within my IPad app that allows the user to configure the application settings (they can also cha开发者_Go百科nge these settings from the IPad settings app). I have the following code:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:externalAddress forKey:@"firstString_preference"];
[defaults setValue:internalAddress forKey:@"secondString_perference"];
[defaults setValue:isConnectedToDemoString forKey:@"firstToggle_preference"];
[defaults setValue:isConnectedToInternal forKey:@"secondToggle_preference"];
[defaults synchronize];

The firstString_preference and secondString_perference are Textfields in the settings bundle and they save to the settings without issue. My problem is the firstToggle_preference and secondToggle_preference are toggle switches in the settings bundle and I cannot seem to set these at all. They always seem to be set to no.

Does anyone know what I am doing wrong? Should i be using a different method for setting Toggle Switch default values?

Thanks in advance


What type are isConnectedToDemoString and isConnectedToInternal. Unless those are NSNumbers, you should use setBool:forKey:.

Also, while setValue:forKey: works for storing object types to the user defaults, your code would be clearer if you used the NSUserDefaults-native setObject:forKey: method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜