gpt4 book ai didi

cocoa - NSBrowser 图像未显示在单元格中

转载 作者:行者123 更新时间:2023-12-03 16:20:08 25 4
gpt4 key购买 nike

我正在使用 NSBrowser View 在查找器类型应用程序中显示文件和文件夹列表。我正在使用 NSBrowser 的新项目基础 Api。

问题是当我尝试在 willDisplayCell 方法中设置图像时。 View 中没有显示任何内容。

代码:

// 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;

}

Apple SimpleCocoaBrowser Example

最佳答案

虽然 cellPrototype 的默认值为 NSBrowserCell,但它似乎使用 NSTextFieldCell。 (macOS 10.14)

要解决此问题,您需要子类 NSBrowserCell 并将子类设置为 cellClass:[_browser setCellClass:[BrowserCell class]];

@interface BrowserCell : NSBrowserCell
@end

@implementation BrowserCell
@end

另一个问题是叶子指示器。它将显示两次,一次来自单元格,一次来自浏览器。

- (void)browser:(NSBrowser *)browser willDisplayCell:(NSBrowserCell *)cell atRow:(NSInteger)row column:(NSInteger)column {
FileSystemNode *parentNode = [self parentNodeForColumn:column];
FileSystemNode *childNode = [parentNode.children objectAtIndex:row];

NSImage *image = node.icon;
[image setSize:NSMakeSize(16, 16)];

cell.image = cell.image;
cell.leaf = YES;
}

雷达://47175910

关于cocoa - NSBrowser 图像未显示在单元格中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31783007/

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