我有一个交替着色的UITableViewCells的UITableView。表格可以编辑:行可以重新排序和删除。当行重新排序或删除时,如何更新单元格交替背景颜色?当行被重新排序或删除时更新交替着色的UITableViewCells
我用这个来绘制交替彩色单元:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row] % 2) {
// even row
cell.backgroundColor = evenColor;
} else {
// odd row
cell.backgroundColor = oddColor;
}
}
但是,当一排被重新排序或删除不会被调用此方法。我不能调用从以下方法[tableView reloadData]
,因为它崩溃的应用程序在一个无限循环:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
// Move the object in the array
id object = [[self.list objectAtIndex:[fromIndexPath row]] retain];
[self.list removeObjectAtIndex:[fromIndexPath row]];
[self.list insertObject:object atIndex:[toIndexPath row]];
[object release];
// Update the table ???
[tableView reloadData]; // Crashes the app in an infinite loop!!
}
是否有人有一个指针或最佳实践的解决方案,以应对重排交替有色细胞的问题?
谢谢
谢谢!这就是诀窍。 – 2009-08-24 10:54:06