Varun Mehta
Varun Mehta

Reputation: 1753

How to create UITableViewCell with dynamic cell height based on its content

I was trying to explore the new feature of dynamic cell height using auto layout, introduced in Xcode 7 using this link. I have one UITableViewCell like this below

Title Label with image view and its description(in UITextView) below

I want cell to adjust its size automatically based on the content in textView and size of image. I set all constraint and given estimatedRowHeight and UITableViewAutomaticDimension as tableview row height. But when i run the app i'm not able to see the UITextView below. Which means that cell height is not getting adjusted dynamically. Do i need to set the cell height programmatically or still i can do it using Auto Layout.

Upvotes: 0

Views: 342

Answers (1)

Mehul Thakkar
Mehul Thakkar

Reputation: 12594

For TextView, it must not be scrollable.

Also, Your constraints are should be provided in such a way that, TableViewCell should get height automatically(there must be vertical spacing constraints between each component, Height of the each component must be there(it may be explicit of implicit height, but it must need to have height)).

Also, estimatedHeight you are providing must be near to actual average height.

If your tableViewCell is getting above things, then and then only it will get dynamic height based on its content.

Upvotes: 2

Related Questions