views:

284

answers:

1

I have a segmented control that changes the data in the table view.

[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];

Let's say that I display 5 rows for tab one, 2 rows for tab two. When the second tab is clicked the first two rows get new values but the old data from tab one for rows 3 to 5 remains. How can I clear them out ? TIA.

A: 

Here's a quick sample code to check out: iPhoneCoreDataRecipes

On topic, here is one of the sweetest provided methods:

// If I want to delete the next 3 cells after the one you click
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSMutableArray* indexPaths = [NSMutableArray array];
  for (int i = indexPath.row + 3; i < indexPath.row + 3; i++)
  {
    [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
  }

  [tableView beginUpdates];
  [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
  [tableView endUpdates];
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

I ran into this problem, if I understand you properly, that updating doesn't remove cells. So just remove them and then call update. Good luck!

TahoeWolverine