为什么UITableViewCell会在改变高度时闪烁?

Bou*_*rne 17 uitableview ios ios7

我有一个简单的UITableView与UITableViewCells.对于tableview中的第0行,我为单元格设置了背景颜色.现在点击第0行我只想要扩展行.为了实现这一点,我使用与此处描述的相同的技术来改变第0行的高度.

现在的问题是细胞膨胀和坍塌,但每个过程都会在细胞上出现难看的闪烁/闪烁.我已尝试使用beginupdates/endupdates并重新加载该行 [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];

是什么导致点击闪烁/闪烁?我怎么摆脱它呢?是的,我忘了提及,我已将单元格的选择样式设置为无.所以这不会造成这种情况.

Kar*_*sza 5

当使用单元格的非不透明背景颜色时,我遇到了同样的问题.解决方案是使用backgroundViewproperty,而不是backgroundColor:

UIView *backgroundView = [[UIView alloc] initWithFrame:cell.frame];
backgroundView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1f];
cell.backgroundView = backgroundView;
cell.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)


Irf*_*fan 0

我认为您不应该在调用 reloadData 之前使用 beginUpdate/endUpdates 方法并手动执行动画。单元格的最终状态(动画后)由数据源定义。我希望这会对您有所帮助。