I did a little demo to isolate a problem I faced in a Project.
When I start the Application, the Cells of the NSOutlineView
are too narrow for the text:
Then I resize the window with the mouse, making it even narrower than the contents of the NSOutlineView
:
When I now enlarge the window again, the problem is cured. From now on the outline works as expected:
This is the main method of my AppDelegate:
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
NSRect frame = NSMakeRect(0., 0., 400., 300.);
NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;
_mainWindow = [[NSWindow alloc] initWithContentRect:frame styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
_mainWindow.title = @"Outline";
NSScrollView *leftScrollView = [[NSScrollView alloc] init];
leftScrollView.hasVerticalScroller = YES;
leftScrollView.hasHorizontalScroller = NO;
leftScrollView.drawsBackground = NO;
leftScrollView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
_mainWindow.contentView = leftScrollView;
NSOutlineView *outlineView = [[NSOutlineView alloc] init];
NSTableColumn *outlineColumn = [[NSTableColumn alloc] initWithIdentifier:@"Menu Item"];
[outlineView addTableColumn:outlineColumn];
outlineView.outlineTableColumn = outlineColumn;
outlineView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleSourceList;
outlineView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
outlineView.headerView = nil;
_outlineDataSourceAndDelegate = [[MROutlineDataSourceAndDelegate alloc] init];
outlineView.dataSource = _outlineDataSourceAndDelegate;
outlineView.delegate = _outlineDataSourceAndDelegate;
leftScrollView.documentView = outlineView;
[_mainWindow makeKeyAndOrderFront:NSApp];
}
Can anyone please explain that odd behavior?
initWithFrame
instead ofinit
with a reasonable large rectangle for both the scroll view and the outline view. That didn't change anything. I also tried settingoutlineView.frame
before adding it to the scroll view, afterwards and aftermakeKeyAndOrderFront
. That was not helpful, either. – Michael Manner