Note that there are some explanatory texts on larger screens.

plurals
  1. PONSTableView's frame inside a NSClipView/NSScrollView using auto layout
    primarykey
    data
    text
    <p>I'm trying to create a <code>NSTableView</code> inside a <code>NSScrollView</code> (the standard configuration, that is) in code, using auto layout. I can't figure out how to make this work.</p> <p>Here's my loadView:</p> <pre><code>- (void)loadView { NSView *view = [[NSView alloc] init]; NSScrollView *tableScroll = [[NSScrollView alloc] init]; NSTableView *fileTable = [[NSTableView alloc] init]; [tableScroll setDocumentView:fileTable]; [tableScroll setHasVerticalScroller:YES]; [tableScroll setHasHorizontalScroller:NO]; fileTable.delegate = self; fileTable.dataSource = self; [fileTable setHeaderView:nil]; [fileTable setAllowsColumnReordering:NO]; NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"column1"]; [fileTable addTableColumn:column]; [tableScroll setTranslatesAutoresizingMaskIntoConstraints:NO]; [fileTable setTranslatesAutoresizingMaskIntoConstraints:NO]; [view addSubview:tableScroll]; NSDictionary *topViews = NSDictionaryOfVariableBindings(tableScroll); [view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableScroll]|" options:0 metrics:nil views:topViews]]; [view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[tableScroll]|" options:0 metrics:nil views:topViews]]; self.fileTable = fileTable; self.view = view; } </code></pre> <p>What happens is that my table view's frame will be always equal to the bounds of the <code>NSClipView</code>. The view is inside a window and gets resized with it, and when I do that it'll resize the scrollview, the clip view and the table, but I can never scroll anywhere.</p> <p>Looking at constraints I get, the <code>NSScrollView</code> gets constraints that set the clip view to fill it, the clip view has no constraints at all and the table view has a bunch of constraints related to the <code>NSTableRowViews</code> inside it.</p> <p>If I add a constraint like <code>|[fileTable(&gt;=500)]</code> to the clip view I'll get 500 pixels of NSTableView, but obviously I don't want to do that.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload