0

In my current project i'm trying to display data in a table View, however the former view does not take up the whole screen just a part of it. It's number of cells depends on an external json and the height of the cell is dynamic. Sadly there is no inbuilt way to use auto-layout(at least i think there's not) to expand the tableView depending on it's cells.

In the following picture there's an example of how one of these table views should look like: example 1

And here's an example how the table view looks like using the autolayout: example 2

Is there a way to expand the tableView to it's full size? I've tried to follow various other questions but none have fully helped me, for exampled i've tried to this solution which sadly did not help me :[, creating a subclass of uitableview and overriding its intrinsicContentSize did not do the trick either.

Any help is much appreciated. -Jorge :]

Community
  • 1
  • 1
J.Paravicini
  • 882
  • 12
  • 39
  • Your link shows how to adjust the height dynamically. You are saying that it does not help you, there are multiple answers there, which ones have you tried? What problems are you running into? "Not working" is not detailed enough for anyone to understand the problem you are running into. –  Apr 04 '17 at 20:55
  • you are right, my question was quite ambigous i will update it, however in for your first point, the first image shows how it shouls look like, but im not using autolayout there and it has significant performance issues, in the second one I do use autolayout but the **entire** tableview does not change height. – J.Paravicini Apr 04 '17 at 20:58
  • Have you implemented the delegate methods for returning the correct height ? https://developer.apple.com/reference/uikit/uitableviewdelegate/1614998-tableview , and in those methods, you can return the correct height for the equivalent row. You should calculate the height you want and return it there. You can also look into these: https://developer.apple.com/reference/uikit/uitableviewautomaticdimension https://developer.apple.com/reference/uikit/uitableviewdelegate/1614926-tableview and implement them see how that works for you. You could also look into UIStackView but i'm not a big fan. :) –  Apr 04 '17 at 21:01
  • That's the point of using autolayout so i don't need to calculate it myself. By using autolayout I don't use the function heightForRowAt and that's making it complicated, however i still want to use autolayout since the cells are perfect this way. – J.Paravicini Apr 04 '17 at 21:04
  • Your tableView does not care about autolayout, autolayout does not calculate dynamic height for you in a tableView, the tableView needs to know the size of the cells it should return in its delegate methods I linked for you. However, if you return **UITableViewAutomaticDimension** for the height then your autolayout will come into play. You can check out some tutorials , this is one example: https://www.raywenderlich.com/129059/self-sizing-table-view-cells –  Apr 04 '17 at 21:08
  • that's exactly the tutorial I used to make this, but even with UITableViewAutomaticDimension i'm not sure how to calculate the height, since in the tutorial he always uses a tableview that takes up the whole screen. – J.Paravicini Apr 04 '17 at 23:45
  • Hmm. It is hard to pinpoint the exact problem for your case, however, I never rely on UITableViewAutomaticDimension sizing for uitableviewcells , for me it never worked good for dynamic content. Might work for static content in some cases etc. can't add anything else :( Good luck! –  Apr 05 '17 at 00:17

0 Answers0