objective-cnstableviewnsscrollview

Weird Scrollbar UI element in programmatically created NSScrollView (objective-c)


i am on macOS, objective-C. Not Swift, not ios.

I have a programmatically created NSScrollView with a nested NSTableView. The scrollbar shows some kind of square element. This element lies above the scrollbar, but is not visible in the view hierarchy debugger. I want it to not show up.

Here is a video:

Weird scroll Bar element

Here is a screenshot from the view hierarchy:

View hierarchy

Here's the code creating the scrollView and and tableView:

// Create tableView
NSTableView* tableView = [[NSTableView alloc] initWithFrame:NSZeroRect];
tableView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleNone;
tableView.translatesAutoresizingMaskIntoConstraints = NO;
tableView.backgroundColor = [NSColor clearColor];
tableView.delegate = self.delegate ? self.delegate : weakSelf;
tableView.dataSource = self.delegate ? self.delegate : weakSelf;
tableView.rowHeight = height; // predefined
tableView.intercellSpacing = NSMakeSize(2, 2);
tableView.headerView = [[NSTableHeaderView alloc] initWithFrame:NSMakeRect(0, 0, 0, CGFLOAT_MIN)];
tableView.columnAutoresizingStyle = NSTableViewUniformColumnAutoresizingStyle;
if (@available(macOS 11.0, *)) {tableView.style = NSTableViewStylePlain;}
self.tableView = tableView;


    
// Create Scroll View
NSScrollView* scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect];

scrollView.verticalScrollElasticity = NSScrollElasticityAutomatic;

// Setup scrollView
scrollView.drawsBackground = NO;
scrollView.hasVerticalScroller = YES;
scrollView.hasHorizontalScroller = YES;
scrollView.autohidesScrollers = YES;
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
scrollView.documentView = tableView;
scrollView.scrollerStyle = NSScrollerStyleLegacy; // Must be legacy (!)
scrollView.automaticallyAdjustsContentInsets = NO;
scrollView.contentInsets = insets;
scrollView.scrollerInsets = NSEdgeInsetsMake(-(insets.top), -(insets.left), -(insets.bottom), -(insets.right)); // insets are predefined
self.scrollView = scrollView;

[self.view addSubview:scrollView];

Any help appreciated


Solution

  • When a table header isn't needed you just can set it to nil. This removes the glitch. Credits to @willeke for pushing me to the right direction