Question

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

Was it helpful?

Solution

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.

OTHER TIPS

I would do it with NSUserDefaults.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top