我已经使用cellForRowAtIndexPath中的以下代码设置了自定义分组tableview样式。每个单元格都有一个新的背景视图,角落根据其在该部分中的位置进行四舍五入。我在整个应用程序和各种视图中使用这种风格,我使用动画添加和删除行。 (使用[tableview insertRowsAtIndexPaths:]等)。自定义UITableViewCell的背景,何时重新加载等
如果某一节的最后一行被插入或删除,我需要能够重新加载单元格背景视图角。我怎么能做到这一点,而无需调用[tableview reloadData]甚至reloadCellsAtIndexPaths?这两个函数都会混淆插入和删除单元格的动画。有什么地方我可以把这个背景角落定义在适当的时候调用?默认的分组tableview如何做到这一点?
对不起,如果这不清楚。要求澄清,我会编辑。谢谢! :)
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];
}
}
会有一个干净的方式来检测单元layoutSubviews或drawRect应该绘制哪些角?我不介意子类UITableViewCell,我只是想不出一种方式,它会帮助.. – Dash 2012-04-19 00:26:56