0

I am using two UITableView. Both UITableView data comes from database. So, there size is not fixed. They are nested in stack view vertically with spacing of 20. The problem is, if data in the first UITableView is less than its height, then it shows blank space between first and second UITableView.

I also tried setting first UITableView height less than or equal to. But still blank space occurs. I want to remove that blank space. I want both tableview to change their height according to their size.

This is how my tableview looks

enter image description here

Fattie
  • 27,874
  • 70
  • 431
  • 719
Abhi
  • 95
  • 8
  • Man that is tricky! – Fattie Jan 22 '18 at 18:49
  • Set a height constraint to your stack, so you can update it, with your data.count. – Gehlen Jan 22 '18 at 19:16
  • can you please explain ? – Abhi Jan 22 '18 at 19:39
  • hey @Gehlen - I'm pretty sure he wants the whole stack to be the whole height of the screen. And I guess, OP wants the *lower* table to be "full" (no scrolling) and the upper table to scroll - if necessary. The very simple answer here is "it's not really possible". It's just bending what autolayout was meant to do. – Fattie Jan 22 '18 at 22:54
  • @Abhi is that what you want? You want your cells to adapt to the size of view, or your stack to the size of your tables? To add a constraint outlet to your stack, first you'll need to set constraint height and width (same of or superView.width) of your stack, and change distribution attribute to 'fill proportionally' or 'equally'. Then drag the height constraint to create the outlet, then follow this answer to update your layout after bind your data: https://stackoverflow.com/questions/42669554/how-to-update-the-constant-height-constraint-of-a-uiview-programatically – Gehlen Jan 23 '18 at 12:12

1 Answers1

4

Not actually an answer to your question.

But are you aware that table views can have sections.

I hate the "section" feature normally, but in fact it would be perfect for you here.

It's very easy to do.

I use stack views very extensively, and I don't know off the top of my head how to make two tables views in a stack view resize. Also, you would have to "decide" which one gets how much space.


Note

enter image description here

it's possible that simply setting align/dist. to Fill, Fill will do what you want. Give it a go!

Community
  • 1
  • 1
Fattie
  • 27,874
  • 70
  • 431
  • 719
  • But, I want two seperate tableview. My second tableview is static. – Abhi Jan 22 '18 at 19:00
  • 1
    You can do that *perfectly* with "sections". Or, try what I said in the "Note". – Fattie Jan 22 '18 at 19:11
  • You should adopt that approach, its what tableView are designed for. – Gehlen Jan 22 '18 at 19:19
  • I tried changing alignment / distribution but still blank space occurs. In my second table view each cell contains different views ex. radiobuttons, dropdowns, checkbox, buttons etc . That's why I am using second tableview as static. – Abhi Jan 22 '18 at 19:23
  • 1
    @Abhi there is no reason why that cannot be done with sections, and I agree with Fattie that that's the way to go in here.. – Milan Nosáľ Jan 22 '18 at 20:04