title: Custom TableViewCell not updating
body: <p>I want to set the checkmark in front of the cell. When I click on the checkmark icon the correct function is called and the datasource is changed. </p>
  
  <p><img src="https://i.stack.imgur.com/PX3OW.png" alt="My Custom cell"></p>
  
  <p>I call <strong>[table reloadData]</strong> and after that even <strong>cellForRowAtIndexPath</strong> is also called but it is always dequeing the old table cell and not reloading it with the new data source..</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString *cellIdentifier = @"CheckboxCell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  
  NSLog(@"cellForRowAtIndexPath row: %d", indexPath.row);
  
  // use CustomCell layout 
  CheckboxCell *checkboxCell;
  
  if(cell == nil) {
      NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CheckboxCell" owner:self options:nil];
  
      for (id currentObject in topLevelObjects){
          if ([currentObject isKindOfClass:[UITableViewCell class]]){
              checkboxCell =  (CheckboxCell *)currentObject;
              break;
          }
      }
  } else {
      checkboxCell =  (CheckboxCell *)cell; // return cell;
  }
  
  Observation *observation = [observations objectAtIndex:indexPath.row];
  
  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  dateFormatter.dateFormat = @"dd.MM.yyyy";
  [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
  NSString *nowString = [dateFormatter stringFromDate:observation.date];
  [dateFormatter release];
  
  NSString *amountString = [[NSString alloc] initWithFormat:@"%d", observation.amount];
  
  checkboxCell.name.text = [observation.organism getNameDe];
  checkboxCell.date.text = nowString;
  checkboxCell.amount.text = amountString;
  checkboxCell.latName.text = [observation.organism getLatName];
  
  // Define the action on the button and the current row index as tag
  [checkboxCell.checkbox addTarget:self action:@selector(checkboxEvent:) forControlEvents:UIControlEventTouchUpInside];
  [checkboxCell.checkbox setTag:observation.observationId];
  
  // Define the action on the button and the current row index as tag
  [checkboxCell.remove addTarget:self action:@selector(removeEvent:) forControlEvents:UIControlEventTouchUpInside];
  [checkboxCell.remove setTag:observation.observationId];
  
  // Set checkbox icon
  if(observation.submitToServer) {
      NSLog(@"CHECKED");
      checkboxCell.checkbox.imageView.image = [UIImage imageNamed:@"check_icon.png"];
  } else {
      NSLog(@"UNCHECKED");
      checkboxCell.checkbox.imageView.image = [UIImage imageNamed:@"checkbox.gif"];
  }
  
  [amountString release];
  [observation release];
  
  return checkboxCell;
  
  
  // Set checkbox icon
  if(observation.submitToServer) {
      NSLog(@"CHECKED");
      checkboxCell.checkbox.imageView.image = [UIImage imageNamed:@"check_icon.png"];
  } else {
      NSLog(@"UNCHECKED");
      checkboxCell.checkbox.imageView.image = [UIImage imageNamed:@"checkbox.gif"];
  }
  
  [amountString release];
  [observation release];
  
  return checkboxCell;
  </code></pre>
  
  <p>}</p>
  
  <p>I think I'm doing something in the cellForRowAtIndexPath wrong.. Can anybody help me?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The first problem could be fixed <em>(Thanks to Maggie)</em>. Now the checkmark is changing the first time correctly. But somehow if I change it on another cell its crashing on the following line:</p>
  
  <pre><code>- (void) checkboxEvent:(UIButton *)sender
  {
  UIButton *button = (UIButton *)sender;
  NSNumber *number = [NSNumber numberWithInt:button.tag];
  
  for(Observation *ob in observations) {
  
      if(ob.observationId == [number intValue]) { // &lt;---- IT'S CRASHING HERE
          ob.submitToServer = !ob.submitToServer;
  
          NSLog(@"New value: %@", (ob.submitToServer) ? @"YES" : @"NO");
      }
  }
  
  [table reloadData];
  }
  </code></pre>
  
  <p>But the observation object isn't nil. Any ideas?</p>