I've set up a custom grouped tableview style using the following code in cellForRowAtIndexPath. Each cell is given a new background view and it's corners are rounded according to its position in the section. I use this style throughout my app and in various views I use animations to add and delete rows. (Using [tableview insertRowsAtIndexPaths:], etc).
If the last row of a section is inserted or removed I need to be able to reload the cells background view corners. How can I do this without calling [tableview reloadData] or even reloadCellsAtIndexPaths? Both of those functions mess up the animations of inserting and deleting cells. Is there somewhere I can put this background corner definition that would get called at the appropriate time? How does the default grouped tableview do this?
Sorry if this is unclear. Ask for clarification and I will edit. Thanks! :)
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:[self styleForCellAtIndexPath:indexPath]
reuseIdentifier:cellIdentifier] autorelease];
// Theme the cell
TableCellBackgroundView *backgroundView = [[TableCellBackgroundView alloc] initWithFrame:cell.frame];
TableCellBackgroundView *selectedBackgroundView = [[TableCellBackgroundView alloc] initWithFrame:cell.frame];
selectedBackgroundView.selectedStyle = YES;
// top row, without header
BOOL header = [self tableView:aTableView heightForHeaderInSection:indexPath.section]!=0;
if (indexPath.row == 0 && (!header || tableTheme==kTableThemeSimple)) {
backgroundView.topRadius = 6;
selectedBackgroundView.topRadius = 6;
}
// bottom row
if (indexPath.row == [self tableView:aTableView numberOfRowsInSection:indexPath.section]-1) {
backgroundView.bottomRadius = 6;
selectedBackgroundView.bottomRadius = 6;
}
cell.backgroundView = backgroundView;
cell.selectedBackgroundView = selectedBackgroundView;
cell.contentView.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor clearColor];
}
}