Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Create your tempSource as follows:</p> <pre><code>NSMutableArray * tempSource = [[NSMutableArray alloc] init]; NSArray *daysOfWeek = [NSArray arrayWithObjects:@"Monday", @"tuestay", @"wednesday", @"thursday", @"friday", @"saturday", @"sunday",nil]; for (int i = 0; i &lt; 7; i++) { NSString *dayOfWeek = [daysOfWeek objectAtIndex:i]; NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:dayOfWeek, @"day", [NSNumber numberWithBool:NO], @"isSelected",nil]; [tempSource addObject:dict]; } [self setSourceArray:tempSource]; [tempSource release]; </code></pre> <p>Then use this Array in cellForRow and didSelect as follows:</p> <p>cellForRow</p> <pre><code>NSDictionary *dayOfWeekDictionary = [sourceArray objectAtIntex:indexPath.row]; cell.textLabel.text = [dayOfWeekDictionary objectForKey:@"day"]; if ([[dayOfWeekDictionary objectForKey:@"isSelected"] boolValue]) [cell setAccessoryType:UITableViewCellAccessoryCheckmark]; else [cell setAccessoryType:UITableViewCellAccessoryNone]; </code></pre> <p>didSelect</p> <pre><code>NSDictionary *dayOfWeekDictionary = [sourceArray objectAtIntex:indexPath.row]; if ([[dayOfWeekDictionary objectForKey:@"isSelected"] boolValue]) [dayOfWeekDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"isSelected"]; else [dayOfWeekDictionary setObject:[NSNumber numberWithBool:YES] forKey:@"isSelected"]; </code></pre> <p>To save this Array use this statement:</p> <pre><code>[[NSUserDefaults standardUserDefaults] setObject:sourceArray forKey:@"array"]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload