How to set dynamic height of cell based on content

后端 未结 4 566
鱼传尺愫
鱼传尺愫 2021-02-04 16:28

I am have an app which requires to display user comments within a table cell. How can I set the dynamic height of the cell based on the contents of the cell like in Instagram?

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 17:13

    Check the UITableViewDelegate documentation.

    - (CGFloat)tableView:(UITableView *)tableView 
                                    heightForRowAtIndexPath:(NSIndexPath *)indexPath
    

    Bear in mind you can't reference the cell from this method, so you want to calculate the height of the contents separately and use it to generate the height.

提交回复
热议问题