UITableViewCell and UISwitches - iPhone SDK

痞子三分冷 提交于 2019-12-25 04:43:28

问题


I am trying to save the states of an UISwitch for each cell in my UITableView. Is there a way to do this? I was thinking of using the NSUserDefault but I'm not too sure about saving the values with a given name and then retrieving that state when the cells are created. Any suggestions would be nice!

Thanks,

Kevin


回答1:


you can try with following sample code;


NSMutableDictionary *dictionay = [[NSMutableDictionary alloc] init];
[dictionay setObject:@"1" forKey:@"firstcell"];
[dictionay setObject:@"2" forKey:@"secondcell"];
.....
.....
[[NSUserDefaults standardUserDefaults] setObject:dictionay forKey:@"dictionay"];

// retrieve values;
NSMutableDictionary *dictionay = (NSMutableDictionay*)[[NSUserDefaults standardUserDefaults] valueForKey:@"dictionay"];
if([[dictionay valueForKey:@"firstcell"] isEqualToString:@"1"])
    switch1.on = YES;
else
    switch1.on = NO;
....
....

I hope, it will help you.




回答2:


I would do it with NSUserDefaults.



来源:https://stackoverflow.com/questions/4234715/uitableviewcell-and-uiswitches-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!