Search code examples
iosswiftuilabelinterface-builderword-wrap

Why is tableView cell not dynamic?


Update:

I have found that the problem occurs because of the date labels top constraint when removed the wrapped text becomes visible. The issue is then the date label is under the other text. Could the real problem be that the cell is not dynamically changing based on the constraints?

I am trying to make text in a UILabel to wrap (at the same time I am trying to make the cell change based on the text)

In the .xib I setup the cell, doing this:

    self.notifInfoLabel.numberOfLines = 0
    self.notifInfoLabel.lineBreakMode = .byWordWrapping

enter image description here sizeToFit is called right before returning the cell in the delegate method.

cell.notifInfoLabel.sizeToFit()//EDIT: turns out this is not needed
    
    return cell
}

The configure method is called on viewDidLoad and right before .reloadData()

func configureTableView() {
    self.tableView.estimatedRowHeight = 82
    self.tableView.rowHeight = UITableView.automaticDimension
}

Currently, the text in the label seems to wrap underneath the date label...

How can I make it work as intended?


Solution

  • You have confusing constraints for Auto layout engine.

    • You want some space from bottom of image view if text is small , And

    • you want text to dynamic in that case label should grow.

    Solution is very simple.

    Bottom constraint of Imageview change = to >= with 750 priority

    Bottom constraint of Date change = to >=

    Hope it is helpful