我做了一个小演示来隔离我在项目中遇到的问题。
当我启动应用程序时,单元格NSOutlineView
对于文本来说太窄了:
然后我用鼠标调整窗口大小,使其比以下内容更窄NSOutlineView
:
当我现在再次放大窗口时,问题就解决了。从现在开始,大纲按预期工作:
这是我的 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];
}
谁能解释一下这种奇怪的行为?