I have a UISwitch, witch among other things, disables a UITextfield.
When using NSUserDefaults, I manage the switch to remember its current state (on/off)
[[NSUserDefaults standardUserDefaults]
setBool:[sender isOn]
forKey:MyPrefKey];
But how to remember that the textfiled was enabled?
Using “setBool” is out of the question, and I can’t figure how to use setObject.
[[NSUserDefaults standardUserDefaults]
setObject:[textField setEnabled:NO]
forKey:MyPrefKey];
Does not work.
Why is using
setBoolout of the question?Either should work, but you should remember to synchronize the user defaults:
Also in your 2nd example there is an error, you should be setting the flag to
[textField isEnabled]instead ofsetEnabled:NO, since this returns void. You also are trying to pass in a primitiveBOOL, it should be wrapped in anNSNumberto be stored as an object