Custom UITableView Dynamic Cell Height

前端 未结 6 632
一个人的身影
一个人的身影 2021-02-06 09:22

I have search and searched through endless blogs and articles on how to determine a dynamic height for a custom UITableViewCell and its detailed text. I have really had a hard t

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 10:04

    Use UITableViewDelegate method:

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
     // here you need to get height of your textlabel in your custom cell. 
     MyCustomCell *myCell = (MyCustomCell *)[tableView cellForRowAtIndexPath:indexPath];
     return myCell.myTextLabel.frame.size.height + 20;
    }
    

    Something like this

提交回复
热议问题