1
votes

I'm trying to use an NSTableView inside an NSTableViewCell and have problems disabling scrolling. The outer tableview visualises a list of objects - in my case a 3D material definition - and inside each cell I use (among other controls) another tableview to represent the properties of the material (which is a dynamic list that can change in size).

  • material A
    • property 1
    • property 2
    • property 3
  • material B
    • property 1
  • material C
  • ...

This works fine except for one thing:

Both tableview's use dynamic row height and this causes the outer table view cell to collapse the inner tableview to a 0px height. Is there a way to disable scrolling for the inner table view and cause it to use enough height to show all elements? What makes it even more complicated is that the properties map to different cell definitions (based on the type of property) and all those cells are setup in Interface Builder. So using an NSView and setting its type to NSTableView to avoid the NSScrollView or doing a programmatic construction of all the controls is not really an option.

Any tips are highly appreciated!

1
It looks like an outline view.Willeke

1 Answers

1
votes

Update: Using TableViews

You can also use NSTableView for what you want do achieve. Unlike UITableView, NSTableView does not do the scrolling itself. It is wrapped inside an NSClipView, which itself is wrapped in an NSScrollView. So you simply extract the tableView out of that and add some constraints.

Interface builder does not support that currently very well. You can't drag the tableView out of its enclosing clipView. But you can open the interface file as source code and remove everything beginning from the scrollView (except the table itself). The tableView should display fine in the Interface Builder (tested on Xcode 9 and 10)

You have to add the constraints in code, but then the tableView should grow by itself.


Since the inner table view does not have to scroll, you can use just NSStackView to layout your views. Then you don’t have to fight the behaviors of NSTableView. If you need an example, feel free to ask!