NSTableView frame inside NSClipView / NSScrollView using auto-layout

I am trying to create NSTableViewinside NSScrollView(standard configuration, that is) in code using an automatic layout. I canโ€™t figure out how to do this.

Here is my loadView:

- (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;
}

What happens is that my table view will always be equal to the borders NSClipView. The view is inside the window and resizes it, and when I do this, it will change the scroll size, view of the clip and table, but I can never scroll anywhere.

, , NSScrollView , , , , NSTableRowViews .

|[fileTable(>=500)] , 500 NSTableView, , , .

+5
1

, , , Id ( ). , " " xib. , NSScrollView NSTableView, , , , translatesAutoresizingMaskIntoConstraints YES. - , , .. .

translatesAutoresizingMaskIntoConstraints NO, , , ( ), . .

, () .

+1

All Articles