我正在使用“SourceList”OutlineView,无法获取“标题”和“数据”NSTableCellViews 的内容来显示。OutlineView 的结构有效,我的应用程序运行并且看起来与http://i.stack.imgur.com/0E4D8.png类似。
这是我的代码:
- (id)init {
self = [super init];
if (self) {
_masterFolder = [[NSMutableArray alloc] init];
MasterFolder *trueMaster = [[MasterFolder alloc] initMaster:@"Categories"];
[_masterFolder addObject:trueMaster];
[trueMaster addChild:[[MasterFolder alloc] initMaster:@"World"]];
[trueMaster addChild:[[MasterFolder alloc] initMaster:@"Sports"]];
[trueMaster addChild:[[MasterFolder alloc] initMaster:@"Local"]];
[trueMaster addChild:[[MasterFolder alloc] initMaster:@"Business"]];
[(MasterFolder *)[trueMaster.children objectAtIndex:0] addChild:[[MasterFolder alloc] initMaster:@"Middle East"]];
}
return self;
}
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
return !item ? [self.masterFolder count] : [[item children] count];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
return !item ? YES : [[item children] count] != 0;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
return !item ? [self.masterFolder objectAtIndex:index] : [[item children] objectAtIndex:index];
}
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
if (![item isKindOfClass:[MasterFolder class]]) {
return [outlineView makeViewWithIdentifier:@"HeaderCell" owner:self];
} else {
NSTableCellView *cellView = [outlineView makeViewWithIdentifier:@"DataCell" owner:self];
cellView.textField.stringValue = [((MasterFolder *)item) name];
return cellView;
}
}
我知道这是此功能的问题:
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
但我不知道要改变什么才能让它工作。我已经在 Stack Overflow 上查看了很多类似的帖子,但无法获得提供的解决方案。