How to set dynamic height of cell based on content

后端 未结 4 563
鱼传尺愫
鱼传尺愫 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:10

    You should give a look at three20 library source code, which offers complex cells like you want to do. It might give you answers on how to do this, even if you do not intend to use it:

    three20 Cells

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-04 17:20

    Combine my dynamic label category here with my dynamic table cell height here. Perfect combination!

    0 讨论(0)
  • 2021-02-04 17:20

    You should refer to this question. The answer is here.

    Dynamic UITableView height in UIPopoverController (contentSizeForViewInPopover)?

    0 讨论(0)
提交回复
热议问题