【发布时间】:2015-04-13 04:13:45
【问题描述】:
我有一个包含 UIView 的自定义 UITableViewCell,我在其中显示了几张图片。
在我的 tableView:cellForRowAtIndexPath: 函数中,我调用 dequeueReusableCellWithIdentifier: 来重用旧的自定义单元格,然后用新图片更新它们。
问题是当我在屏幕上快速滚动时,我看到旧图片在加载新图片之前闪烁,这很不吸引人。
我已尝试通过以下方式解决此问题:
- 在自定义TableViewCell实现文件中实现prepareForReuse;这导致相同的三个 UIView 一遍又一遍地出现,在这种情况下,新图片完全停止加载
- 在调用 dequeueReusableCellWithIdentifier 后立即清除 UIView,方法是使用 for 循环删除所有子视图;该应用现在需要很长时间才能加载图片。
解决此问题的最佳方法是什么,为什么在我尝试的修复中会出现上述错误?这是我当前的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"Blah";
blahCell *someCell = (blahCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!someCell) {
//initialize cell
} else {
someCell.imageContainerView = nil;
}
... (other code here)
}
【问题讨论】:
标签: objective-c uitableview uiview uiimageview reuseidentifier