Retrieve and store boolean values in uitableview ios
I have a list with a few rows, each row containing a switch. I would like to store the boolean values of the list (ever开发者_开发技巧y time one is clicked) to nsuserdefaults , however im unsure of how to obtain each value. The switch is a UICustomSwitch. Thanks in advance!
Store booleans with
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setBool:NO forKey:@"myKey"];
Retrieve booleans with
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs boolForKey:@"myKey"];
To integrate this with a swtich, you can do the following;
Store booleans with
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setBool:mySwitch.on forKey:@"myKey"];
Retrieve booleans with
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[mySwitch setOn:[prefs boolForKey:@"myKey"] animated:YES];
精彩评论