skip to Main Content

My tableviewcell height stays fixed even though I do the following:

tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 150

I have one imageview and one label inside the cell and I gave constraints to each side.

Also, I tried:

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableView.automaticDimension
}

I need a fixed height for my cell. It doesnt need to be dynamic. But no matter what i tried the height stays around 50px.

Any help?

2

Answers


  1. you can set the height you want with heightForRowAtIndexPath, hopefully that helps

    Login or Signup to reply.
  2. Setting automaticDimension is based on using auto layout in your cells.

    This means you must add a NSLayoutConstraint to all sides of a UILabel (or any other control you use in your cells) and the UITableViewCell container in interface designer or in code. In case of a label, configure setting ‘Lines’ to 0 and ‘Line Break’ to Word Wrap.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search