0

enter image description here

I have a tableView Cell like this in storyboard as shown in above image.

I defined required things in controller necessary for dynamic cell height like this :

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

    return UITableViewAutomaticDimension
}

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

and in viewDidLoad()

self.tblView.rowHeight = UITableViewAutomaticDimension
self.tblView.estimatedRowHeight = 250

But i am getting output like this :

enter image description here

It seems there are some autolayout conflicts here thats why its occurring or might be i am missing something. Actually there are lots of elements in this cell & posting constraints screenshots of all will be bit lengthy. If anyone could tell how to approach for resolving this or if u need constraint images I will add in question.

PS: If anyone is coming here I would recommend read below mentioned answers , it will help you:

Shivam Tripathi
  • 1,405
  • 3
  • 19
  • 37
  • 1
    I can confirm this is due to AutoLayout, have you got any warnings in the console at launch ? – AnthoPak Aug 01 '18 at 08:10
  • Look like a really complex cell, it should be best if you can upload your storyboard file and confirm all the label that can have dynamic height – Tj3n Aug 01 '18 at 08:10
  • Automatic dimension dependent on Autolayout constraint if it is wrong your cell will always be wrong height – Prashant Tukadiya Aug 01 '18 at 08:12
  • @AnthoPak yes i got this warning : Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead. – Shivam Tripathi Aug 01 '18 at 08:12
  • 1
    Are you sure that you did setup the constraints properly? Related: https://stackoverflow.com/questions/30299319/why-uitableviewautomaticdimension-not-working – Ahmad F Aug 01 '18 at 08:14
  • So that's it, you should review all your constraints to make sure the expected height of the cell is good. Consider removing your constraints and trying again – AnthoPak Aug 01 '18 at 08:14
  • I don't find anything similar between the 2 images. Are they supposed to look the same? – Rakesha Shastri Aug 01 '18 at 09:03
  • Make sure the compiler will be able to tell the height of the cell with your constraints. Like if you have a label in a contentView label.top -> contentView.top, label.height = 10, label.bottom -> contentView.bottom => cellHeight = 10. – Rakesha Shastri Aug 01 '18 at 09:04
  • Can you please show the constraints you have given to that cell? – iPeter Aug 01 '18 at 10:29
  • Thanks all for your valuable comments, A View is causing conflict . Problem got resolved. – Shivam Tripathi Aug 01 '18 at 11:49

0 Answers0