Search code examples
iosuitableviewswiftcustom-cell

Why isn't my tableview row height being set properly?


I am trying to make a table view with a dynamic cell containing an image view and 3 labels in Interface Builder, but for some reason the table view row height isn't being set properly and all the content is being cut off. This is the only code for it:

override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 100.0

}

And my interface builder constraints are almost similar to the ones shown below from a Ray Wenderlich tutorial (http://www.raywenderlich.com/87975/dynamic-table-view-cell-height-ios-8-swift)

enter image description here

Here is a sample of the simulator output: enter image description here

If anyone has any insight on how I can fix this, I'd be more than happy to hear you out. As you probably guessed, I am trying to make it so that the cell height expands according to the subtitle length (a la Twitter) but to no avail :( Thanks!

Update: It looks a bit better now but still not expanding as the UILabel expands :(


Solution

  • Solved it! My constraints were correct but for some odd reason the tableView wasn't updating. Adding the following code seemed to make it fine:

    override func viewDidAppear(animated: Bool) {
            tableView.reloadData()
        }
    

    If you have any better suggestions feel free!