试图强制重绘UITableViewCell

时间:2010-04-24 17:12:35

标签: iphone uiview uitableview redraw

我在http://news.selectstartstudios.com/beveled-uitableviewcells/的Beveled UITableViewCells上发现了这篇文章。我正在使用这种技术来减小细胞的宽度,并且在大多数情况下它的效果很好。

但是,我有一个小问题。有时细胞不能正确重绘。例如,即使一个单元格应该是一个“中间”单元格,它也会被绘制为“顶部”单元格:yfrog.com/f1screenshot20100424at100

我该如何解决这个问题?

我尝试通过[cell setNeedsDisplay],[cell setNeedsLayout],[tableView reloadRowAtIndexPath:withAnimation:],[cell drawrect:]和[tableView drawRect:atIndexPath]强制细胞重绘。我没有想法。

再次感谢!

2 个答案:

答案 0 :(得分:24)

原来我需要在cellForRowAtIndexpath的末尾调用[cell.backgroundView setNeedsDisplay]。

答案 1 :(得分:1)

遇到同样的问题,因为我的一些cellForRowAtIndexpath是在后台线程中。在这种情况下的解决方案是强制任何直接的单元子视图更新到主线程:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    if (cell.tag == indexPath.row){
       // data retrieval that may block main thread and cause temp freeze...
       dispatch_async(dispatch_get_main_queue(), ^{
          // update any cell subviews here
       }
    }
});
相关问题