0

I have a UITableView defined in a storyboard with a UITableViewCell that contains another UITableView as part of its content with a UITableViewCell defined in it all in a storyboard.

IB image

Both content views are fully specified by auto layout. The nested table however always has a frame height of zero. If I turn on a height for the nested table you can see all of the content so I know it is there; however without the hard coded height its always 0. I've done this before but for whatever reason I am missing something.

The top level table works fine. The nested table properly loads its cells. I've done the trick of

    removalTable.estimatedRowHeight = 127
    removalTable.rowHeight = UITableViewAutomaticDimension
    removalTable.setNeedsLayout()
    removalTable.reloadData()

I'm not really new to SO but for whatever reason I can't get my openID to work.

  • When I've nested tableviews, I call `layoutIfNeeded` on the child tableview instead of `reloadData`. This lays out the child immediately, so the parent knows its child's height when it comes to layout the parent (I'm pretty sure that is how it works). So assuming your constraints are all correct, calling `removalTable.layoutIfNeeded()` may help. – j.f. Jun 01 '16 at 18:35
  • I tried that but it didn't affect anything. In the end I went with something other than a nested table view. –  Jun 02 '16 at 15:04
  • Oddly enough it set up the scroll view height correctly but not the table frame itself. –  Jun 02 '16 at 15:04
  • Probably a good idea to find a different solution. Glad you were able to work something out. While nested tableviews can work, they can be very finicky. Having struggled with them in the past, I try to stay away from them now. – j.f. Jun 02 '16 at 15:08

1 Answers1

0

I have seen this error a lot of times. it is probably because you are not setting good constraints inside the cell you are displaying. What you need to check?

  1. you have an anchor to the top and the bottom at least.
  2. you have a fixed height in one view of your content.

Maybe this post can help you: Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

I hope it helps you.

Community
  • 1
  • 1
Gabriel Goncalves
  • 5,132
  • 3
  • 25
  • 34
  • You can see the constraints in the image. They are fully specified for the content view. –  Jun 01 '16 at 16:05
  • That post does not discuss a nested table which is where the issue lies. –  Jun 01 '16 at 16:05
  • yes but the problem since to be the cell that contains that tableview. You need to specify a height for that tableview which is inside that cell. @BigHenry – Gabriel Goncalves Jun 01 '16 at 16:56