Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Cell Size in Table View from a custom Xib [duplicate]

(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.

Custome Table View Cell

Separate Table View Controllers implementing custom xib

Height of Table View 1

like image 900
Sean Avatar asked Oct 10 '15 22:10

Sean


1 Answers

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.

like image 139
Mike Taverne Avatar answered Sep 19 '22 18:09

Mike Taverne