title: iOS - how to set a checkmark in a UITableView the first time the table is loaded
body: <p>I am an iOS newbie. I am using a checkmark to in a UITableView, and storing the checked value in a local database. When I load the app for the first time, I want to set the value of the checkmark depending on which value exists in the db. How would I do that? Presently this is what I do -</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString *CellIdentifier = @"Cell";
  
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
  }
  if ([indexPath compare:self.lastIndexPath] == NSOrderedSame) 
  {
      cell.accessoryType = UITableViewCellAccessoryCheckmark;
  } 
  else 
  {
      cell.accessoryType = UITableViewCellAccessoryNone;
  }
  // Set up the cell...
  NSString *cellValue = [[self countryNames] objectAtIndex:indexPath.row];
  cell.textLabel.text = cellValue;
  
  return cell;
  }
  </code></pre>
  
  <p>and then in didSelectRowAtIndexPath -</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  
  // some stuff
  self.lastIndexPath = indexPath;
  [tableView reloadData];
  }
  </code></pre>