iOS: TableView inside ScrollView


Gerriet M. Denkmann
 

iOS 11, Xcode 10

I have a view with an UIScrollView, which is bound on all 4 sides to the save area.

This ScrollView contains:
UILabel
UITableView
UILabel

The problem: if the TableView does *not* have a definite height, then Xcode complains: “The ScrollView needs y-position or height fixed”.

But the whole point of the TableView is that the number of rows can change at run time.

The effect I want is similar to Settings → Wi-Fi where unter “Choose a Network” there is a dynamically changing list of names.
And the whole page can be scrolled vertically.

How to achieve this?

Gerriet.


Steve Mills
 

On Sep 18, 2018, at 03:47:36, Gerriet M. Denkmann <g@mdenkmann.de> wrote:

iOS 11, Xcode 10

I have a view with an UIScrollView, which is bound on all 4 sides to the save area.

This ScrollView contains:
UILabel
UITableView
UILabel

The problem: if the TableView does *not* have a definite height, then Xcode complains: “The ScrollView needs y-position or height fixed”.

But the whole point of the TableView is that the number of rows can change at run time.

The effect I want is similar to Settings → Wi-Fi where unter “Choose a Network” there is a dynamically changing list of names.
And the whole page can be scrolled vertically.
That's simply a table view with static sections, and each section has a set number of rows. The Choose a Network section has variable number of rows, added programmatically. You don't need to add these things to a scroll view - the table view takes care of that.

--
Steve Mills
Drummer, Mac geek


Quincey Morris
 

On Sep 18, 2018, at 01:47 , Gerriet M. Denkmann <g@...> wrote:

The problem: if the TableView does *not* have a definite height, then Xcode complains: “The ScrollView needs y-position or height fixed”.

Keep in mind that UITableView is a kind of UIScrollView, which isn’t how NSTableView works. Your intended solution nests a scroll view within a scroll view, which is kind of hard to know how to lay out satisfactorily.

Steve’s suggestion of a table view with 3 sections is a good solution.


Gerriet M. Denkmann
 

On 19 Sep 2018, at 07:16, Quincey Morris <quinceymorris@rivergatesoftware.com> wrote:

On Sep 18, 2018, at 01:47 , Gerriet M. Denkmann <g@mdenkmann.de> wrote:

The problem: if the TableView does *not* have a definite height, then Xcode complains: “The ScrollView needs y-position or height fixed”.
Keep in mind that UITableView is a kind of UIScrollView, which isn’t how NSTableView works. Your intended solution nests a scroll view within a scroll view, which is kind of hard to know how to lay out satisfactorily.

Steve’s suggestion of a table view with 3 sections is a good solution.
Yes. It certainly looks better than my current work-around:

NSLayoutConstraint *heightConstraint = self.tableView.constraints.firstObject;
heightConstraint.constant = nbr of rows in table * row height;

The documentation says: “See the Settings application for examples of grouped tables.”

So I am going to implement this.

Thanks a lot.


Kind regards,

Gerriet.