iOS8: Possible to use “tableview.rowHeight = UITableViewAutomaticDimension” for static cells?

前端 未结 8 1004
慢半拍i
慢半拍i 2020-12-14 17:00

I have a UITableView that has five static cells. I need the cell height of one cell to adjust automatically to its contents, which is one UILabel.

Is there any way I

8条回答
  •  情话喂你
    2020-12-14 17:46

    For iOS 8, I found out that you cannot do the same strategy as for Dynamic Table View Cell.

    To automatically adjust the height of static cells, I implement these two UITableViewDelegate methods:

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return UITableViewAutomaticDimension;
    }
    
    -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 44;
    }
    

    Hope it helps.

提交回复
热议问题