UITableViewCell's contentView gets unwanted "height==44" constraint

I had the same issue and fixed it setting the auto resizing mask of the cell like this:

override func awakeFromNib() {
    super.awakeFromNib()
    self.contentView.autoresizingMask = .flexibleHeight
}

Also in the controller I set the estimated height and tell the table view to use automatic dimension (in the viewDidLoad method:

    self.tableView.estimatedRowHeight = 120
    self.tableView.rowHeight = UITableView.automaticDimension

These links helped:

http://useyourloaf.com/blog/2014/08/07/self-sizing-table-view-cells.html

Auto layout constraints issue on iOS7 in UITableViewCell

Hope this helps!


To tack on to the accept answer- after months of trying to get iOS 8's automatic cell sizing to work I discovered an important caveat. The 'estimatedRowHeight' property MUST be set. Either via the tableView directly or by implementing the delegate methods. Even if there's no way to determine a valid estimate, simply providing a value other than the default (0.0) has demonstrably allowed iOS 8's cell layout to work in my testing.


Regarding to the "solution" mentioned in the edit in the question (setting the contentView frame to something big temporarily), here's proof this is a good "solution": https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/blob/master/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift

        // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception.
        // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below.
        //      See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188
        // contentView.bounds = CGRect(x: 0.0, y: 0.0, width: 99999.0, height: 99999.0)

It's hacky but it seems to work.