How to make a custom drawn UITableViewCell resize properly?

前端 未结 4 1002
既然无缘
既然无缘 2021-02-09 11:19

For performance reasons, I draw the strings for my UITableViewCell in a custom view that overrides its drawRect method to draw strings directly in the view rectangle using NSStr

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-09 11:53

    I had this problem too, and in my case I fixed it by handling the 2 states in my drawRect method, one while editting, the other while not. In other words I accounted for the size of the delete button, and got my UI to repaint the cell differently. I'm not sure if it's the most efficient way to go, but here is the code that I used to force a repaint:

    -(void)_refreshTableAndCells{
        //refresh the table
        [myCustomTableView reloadData];
        //refresh all the visible cells
        for (UITableViewCell *cell in myCustomTableView.visibleCells){
            LocationCellView *locationCell = [cell.contentView.subviews objectAtIndex:0];
            [locationCell setNeedsDisplay];
        }
    
    }
    

    I'm an Objective-C n00b though, so I'd be more than happy for someone to suggest a better way than this.

提交回复
热议问题