我正在使用 NSBrowser 视图在查找器类型应用程序中显示文件和文件夹列表。我正在为 NSBrowser 使用新的 Item Base Api。
问题是当我尝试在willDisplayCell
方法中设置图像时。视图中不显示任何内容。
代码:
// This is a utility method to find the parent item for a given column. The item based API eliminates the need for this method.
- (FileSystemNode *)parentNodeForColumn:(NSInteger)column {
if (_rootNode == nil) {
_rootNode = [[FileSystemNode alloc] initWithURL:[NSURL fileURLWithPath:@"/Users/kiritvaghela"]];
}
FileSystemNode *result = _rootNode;
// Walk up to this column, finding the selected row in the column before it and using that in the children array
for (NSInteger i = 0; i < column; i++) {
NSInteger selectedRowInColumn = [_browser selectedRowInColumn:i];
FileSystemNode *selectedChildNode = [result.children objectAtIndex:selectedRowInColumn];
result = selectedChildNode;
}
return result;
}
- (void)browser:(NSBrowser *)browser willDisplayCell:(NSBrowserCell *)cell atRow:(NSInteger)row column:(NSInteger)column {
FileSystemNode *parentNode = [self parentNodeForColumn:column];
FileSystemNode *childNode = [parentNode.children objectAtIndex:row];
[cell setTitle:childNode.displayName];
cell.image = node.icon;
}