I use below code to add constraints programatically, no story board used
cell.descriptionDetail.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor, constant: 15).isActive = true
cell.descriptionDetail.topAnchor.constraint(greaterThanOrEqualTo: cell.contentView.topAnchor, constant: 20).isActive = true
cell.descriptionDetail.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor, constant: -20).isActive = true
cell.descriptionDetail.bottomAnchor.constraint(greaterThanOrEqualTo: cell.contentView.bottomAnchor, constant: 10).isActive = true
Now i use this in viewDidLaod
detailTableView.rowHeight = UITableView.automaticDimension
detailTableView.rowHeight = 40
even if i remove height constraints on all cell the row height does. not adjust, if i remove
detailTableView.rowHeight = 40
and add detailTableView.estimatedRowHeight = 40
, i get error, currently this is what happens , content overlapping cells
UPDATE MY ENTIRE CODE OF FILE WHERE THE CELL IS BEING CREATED AND CONSTRAINED
let cell = detailTableView.dequeueReusableCell(withIdentifier: String(describing: TextOnlyCell.self), for: indexPath) as! TextOnlyCell
view.addSubview(cell.descriptionDetail)
view.addSubview(cell)
cell.descriptionDetail.numberOfLines = 0
cell.descriptionDetail.lineBreakMode = .byWordWrapping
cell.descriptionDetail.translatesAutoresizingMaskIntoConstraints = false
cell.descriptionDetail.widthAnchor.constraint(greaterThanOrEqualToConstant: 100).isActive = true
cell.descriptionDetail.heightAnchor.constraint(greaterThanOrEqualToConstant: 20).isActive = true
///Constraints
cell.descriptionDetail.leadingAnchor.constraint(equalTo: cell.leadingAnchor, constant: 15).isActive = true
cell.descriptionDetail.topAnchor.constraint(greaterThanOrEqualTo: cell.topAnchor, constant: 10).isActive = true
cell.descriptionDetail.trailingAnchor.constraint(equalTo: cell.trailingAnchor, constant: -5).isActive = true
cell.descriptionDetail.bottomAnchor.constraint(greaterThanOrEqualTo: cell.bottomAnchor, constant: 10).isActive = true
cell.descriptionDetail.text = restaurant.description
return cell
heightForRow
? – Jawad Ali