gpt4 book ai didi

objective-c - 基于 View “Source List” NSOutlineView 不显示项目的图标和标题

转载 作者:太空狗 更新时间:2023-10-30 03:52:43 28 4
gpt4 key购买 nike

将 NSOutlineView cell-based 更改为 view-based 后,它不再显示文件系统树的图标和标题。这是我的代码:

- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
if ([[tableColumn identifier] isEqualToString:@"name"])
return [(ImageAndTextCell *)cell setTextFieldImage:[item icon]];
}

- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
return [((ConstructorFSEntity *)item) title];
}

- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
if ([item isKindOfClass:[FSEntity class]]) {
return [outlineView makeViewWithIdentifier:@"HeaderCell" owner:self];
} else {
return [outlineView makeViewWithIdentifier:@"DataCell" owner:self];
}
}

我还有一个问题。如何将枚举项(文件系统项的数组)放入单元格“DataCell”,并将“HeaderCell”声明为父文件夹(组)并为其分配标题(例如@“Root Folder”)和路径类。因为,现在以前基于 View 的方法只在“HeaderCell”或“DataCell”中显示枚举项,当我尝试为“HeaderCell”分配某个值时,应用程序崩溃了。你能帮我解决这个问题吗?

最佳答案

要显示项目的标题和图标,只需更改此方法即可

- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item

如下:

- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
if (![item isKindOfClass:[FSEntity class]]) {
return [outlineView makeViewWithIdentifier:@"HeaderCell" owner:self];
} else {
NSTableCellView *cellView = [outlineView makeViewWithIdentifier:@"DataCell" owner:self];
[(ImageAndTextCell *)cellView.textField.cell setTextFieldImage:[item icon]];
cellView.textField.stringValue = [((FSEntity *)item) title];
return cellView;
}
}

关于objective-c - 基于 View “Source List” NSOutlineView 不显示项目的图标和标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12123925/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com