【发布时间】:2012-04-19 00:25:05
【问题描述】:
我使用 cellForRowAtIndexPath 中的以下代码设置了自定义分组表视图样式。每个单元格都有一个新的背景视图,并且它的角根据其在该部分中的位置进行了圆角处理。我在整个应用程序中使用这种风格,在各种视图中我使用动画来添加和删除行。 (使用 [tableview insertRowsAtIndexPaths:] 等)。
如果插入或删除部分的最后一行,我需要能够重新加载单元格背景视图角。我怎样才能做到这一点而不调用 [tableview reloadData] 甚至 reloadCellsAtIndexPaths?这两个函数都会弄乱插入和删除单元格的动画。有没有什么地方可以放置这个在适当的时间被调用的背景角定义?默认的分组表视图是如何做到的?
抱歉,如果不清楚。要求澄清,我会编辑。谢谢! :)
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,我只是想不出有什么帮助..
标签: iphone objective-c ios uitableview