-1

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

cyril
  • 3,020
  • 6
  • 36
  • 61

3 Answers3

0

In the UIViewController which has your UITableView as a child view(or it can be UITableViewController) make your table view cell height "100" too.I think it is 44 now?

Also if it not set already, set your subtile's "Lines" property to "0" in Interface Builder to make it self-sizing.

Okhan Okbay
  • 1,374
  • 12
  • 26
0

You are using the estimatedrow height. There is an another delegate method for height that you have to use. It is just rowheight delegate. Use heightForRowAtItem index version of objective c in swift.

Vinayak Parmar
  • 608
  • 10
  • 18
0

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!

cyril
  • 3,020
  • 6
  • 36
  • 61