开发者

Trying to force redraw of UITableViewCell

开发者 https://www.devze.com 2022-12-27 20:42 出处:网络
I found this post on Beveled UITableViewCells from http://news.selectstartstudios.com/beveled-uitableviewcells/. I\'m using the technique to reduce the width of the cells, and for the most part it wor

I found this post on Beveled UITableViewCells from http://news.selectstartstudios.com/beveled-uitableviewcells/. I'm using the technique to reduce the width of the cells, and for the most part it works great.

However, I have a small problem. Sometimes the cells are not redrawn properly. For example, even though a cell is supposed to be a "middle" cell, it is drawn as a "top" cell: yfrog.com/f1screensh开发者_运维百科ot20100424at100

How can I fix this?

I have tried forcing the cell to redraw via [cell setNeedsDisplay], [cell setNeedsLayout], [tableView reloadRowAtIndexPath:withAnimation:], [cell drawrect:], and [tableView drawRect:atIndexPath]. I am out of ideas.

Thanks again!


Turns out I needed to call [cell.backgroundView setNeedsDisplay] at the end of cellForRowAtIndexpath.


Ran into the same problem because some of my cellForRowAtIndexpath was in a background thread. The solution in this case is to force any direct cell subview updates into the main thread:

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
       }
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消