Reputation: 12431
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?
Basically, I have texts and comments that have different length in different cells. Can anyone advise me on how I can implement the dynamic height method (like instagram)?
Upvotes: 8
Views: 22149
Reputation: 256
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.
Upvotes: 19
Reputation: 12325
You should refer to this question. The answer is here.
Dynamic UITableView height in UIPopoverController (contentSizeForViewInPopover)?
Upvotes: 1
Reputation: 14419
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:
Upvotes: 1