Dynamic Cell Size in Table View from a custom Xib
Make sure you have set constraints within your tableview cell that will force it to expand to the height you want.
In particular, make sure you have vertical constraints between the top of the cell and "Hello", between "Hello" and "Language", and between "Language" and the bottom of the cell.
If this doesn't work, you might try doing this in a prototype cell within one of your table view controllers, just to see if perhaps there is an issue using xibs for dynamic cells.
Related videos on Youtube
Comments
-
Sean almost 2 years
(Warning, I'm an iOS newbie.) I have created a custom Table View Cell and have registered it, and implemented it, on two seperate Table View Controllers. When I run the app the custom xib content is truncated by the parent Table Cell View height.
I'd like for each Table View to dynamically determine its height based on the height of the content in the custom Table View Cell xib.
I have tried adding
myTableView.rowHeight = UITableViewAutomaticDimension myTableView.estimatedRowHeight = 160.0
to one of the Table View Controller's viewDidLoad function, but no luck.
-
Sean over 8 yearsThanks Mike, that worked. Must have missed that all too important final constraint on the bottom. The "UITableViewAutomaticDimension", and "estimatedRowHeight" needed to exist as well.
-
Claus over 7 yearsI confirm it: you need "UITableViewAutomaticDimension", "estimatedRowHeight" AND setting the internal constrains for the height in the table cell .xib files
-
C0D3 about 6 yearsI also wanna point out that the constraints need to be hooked up to the top and bottom contentView and NOT to the safe area.
-
Ahsan over 5 yearsThanks Mike it worked
-
MrAn3 about 4 yearsI was having a problem because I had: textView.translatesAutoresizingMaskIntoConstraints = true in a UITextView inside my custom cell class. Removing it (along with your suggestions) solved it.