Search code examples
iosswiftuitableviewnslayoutconstraintsnapkit

Getting warning when trying to use SnapKit to layout UILabels in a custom UITableViewCell


I'm trying to use SnapKit to layout UILabels in a custom UITableViewCell. If I put in this code:

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)

    self.contentView.snp.makeConstraints { (make) -> Void in
        make.height.equalTo(104)
    }
...}

I get a warning: LayoutConstraints] Changing the translatesAutoresizingMaskIntoConstraints property of the contentView of a UITableViewCell is not supported and will result in undefined behavior, as this property is managed by the owning UITableViewCell.

This is my first time using SnapKit so not sure if there is a way to keep SnapKit from setting the translatesAutoresizingMaskIntoConstraints property?

This is just the first constraint I'm adding, but I want to layout several labels in the cell.


Solution

  • ContentView either get's it's height from heightForRowAt or from inner elements if you use dynamic table cells , If you want static height

    func tableView(_ tableView: UITableView, 
         heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 104
    }