I'm using NSBrowser view to show list of files and folder in finder type app.I'm using new Item Base Api for NSBrowser.
The problem is that when I try set image in willDisplayCell
method. Nothing is displayed in view.
Code:
// 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;
}
While the default value for cellPrototype is NSBrowserCell, it seems to use a NSTextFieldCell. (macOS 10.14)
To fix this, you need to subclass NSBrowserCell and set the subclass as cellClass:
[_browser setCellClass:[BrowserCell class]];
Another issue is the leaf indicator. It will be shown twice, once from the cell and once from the browser.
radar://47175910