views:

127

answers:

1

Hi all,

I'm having a strange problem with UITableView. When the user taps the Edit button, the tableview (which is a grouped view with multiple sections) is supposed to show delete buttons for each row--except for the final row in each section, which has a green add button.

When a user taps the green button, a new row is inserted, but now the final row gets a delete button. Even stranger, that delete button ACTS like an add button. So it seems there's a drawing glitch, rather than a problem in assigning the correct style. (Extensive NSLogging shows that the last cell is getting the Insert editing style correctly.)

I've tried setting setNeedsDisplay on the cell and the tableView, I've tried reloading that section/row/the entire table, but the issue persists. Any ideas on how to get UITableView to explicitly redraw the editing controls?

A: 

I'm pretty sure you can just implement this in your UITableView delegate to prevent it from editing the last row:


-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  // Return NO if you do not want the specified item to be editable.
  if (indexPath.row != lastRow) // whatever your last row is
    return YES;
  }
  return NO;
}
taber