开发者

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];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜