我的应用程序有一个基于单元格的NSOutlineView,其数据源是NSMutableArray。在初始化中,我的应用程序从文本文件加载NSMutableArray。然后,NSOutlineView将填充NSMutableArray。
NSOutlineView在OSX 10.10之前填充了NSMutableArray。在OSX 10.10中,NSOutlineView为空,即不显示任何数据。我把NSLog放在数据源方法中,发现在10.10中,只有 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item被调用。不调用其他3个数据源方法。
我没有OSX 10.10来调试此问题。请帮忙。
@interface AppController : NSObject {
...
IBOutlet NSOutlineView *outlineViewCmdSet;
}
#pragma OutlineView for CmdSet
// Data Source methods
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
return (item == nil) ? [cmdTree count] : [item numberOfChildren];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
return (item == nil) ? YES : [item isExpandable];
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
return (item == nil) ? [cmdTree objectAtIndex:index] : [[item children] objectAtIndex:index];
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
return [item nodeName];
}
// Delegate methods
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item {
return NO;
}
// Drag command to ScriptEditor
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard {
// Single Selection. items array has only 1 object
TreeItem *item = [items objectAtIndex:0];
if ([item isExpandable]) // Group Name
{
return NO;
}
else // Command Name
{
// Copy the Command Name to the pasteboard.
[pboard declareTypes:[NSArray arrayWithObject:CommandTreeViewDataType]
owner:self];
[pboard setString:[item nodeName] forType:CommandTreeViewDataType];
return YES;
}
}
答案 0 :(得分:0)
谢谢大家。我已经通过将可变数组的初始化从applicationDidFinishLaunching转移到awakeFromNib来解决了这个问题。
奇怪的是,在10.10之前,在OutlineView数据源方法之前调用applicationDidFinishLaunching,但在10.10之前没有。有人对此有任何想法吗?