所以我承认我对 cocoa 完全是菜鸟,所以我提出一个菜鸟问题。我可能只是在某个地方错过了明显的愚蠢之处,但我似乎无法让我的表填充数据。
我正在关注 table view playground示例,但每次我尝试模仿基本 TableView 窗口时,第一行都会变成我添加的行数的高度(至少看起来是这样。这是我的代码:
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
NSString *identifier = [tableColumn identifier];
if ([identifier isEqualToString:@"filename"]) {
// We pass us as the owner so we can setup target/actions into this main controller object
NSTableCellView *cellView = [fileBrowserTable makeViewWithIdentifier:identifier owner:self];
// Then setup properties on the cellView based on the column
cellView.textField.stringValue = [fileList filenameAtIndex:row];
cellView.imageView.objectValue = [[NSWorkspace sharedWorkspace] iconForFile:[fileList fullPathAtIndex:row]];
return cellView;
}
else if ([identifier isEqualToString:@"path"]) {
NSTextField *textField = [fileBrowserTable makeViewWithIdentifier:identifier owner:self];
textField.objectValue = [fileList pathAtIndex:row];
return textField;
}
else if ([identifier isEqualToString:@"preview"]) {
NSTextField *textField = [fileBrowserTable makeViewWithIdentifier:identifier owner:self];
textField.objectValue = [fileList previewAtIndex:row];
return textField;
}
return nil;
}
我认为值得一提的是,当使用旧式文本字段单元格时,我在显示数据时没有问题(当然上面的代码在这种情况下是不同的),所以我确信这不是我的数据结构的问题持有值(value)观。我还设置了正确的委托(delegate)和数据源
使用“文件名”标识符的单元格使用“图像和文本表格 View 单元格”,而其他单元格仅使用“文本表格单元格 View ”。它们都不起作用,所以我猜我设置 table 的方式有问题。但是,当将我的表与示例的表进行比较时,它只是一个吐槽反射(减去标识 rune 件名)。
我注意到我不太明白的一件事是该示例说:
The NSTableView has two reuse identifier assocations: "MainCell" and "SizeCell" are both associated with the nib ATBasicTableViewCells.xib
我不太明白这个说法。然而话虽这么说,该示例不包含任何 ATBasicTableViewCells.xib,也没有我能找到的任何与之相关的内容(代码或 ib)。
最佳答案
您是否尝试将NSTableView
的rowSizeStyle设置为NSTableViewRowSizeStyleCustom
?
[更新]重新阅读您的问题,我不清楚您的问题是什么。我给出的解决方案与每个单元格的大小问题有关,除非将 rowSizeStyle 设置为自定义,否则不会考虑该问题。
关于macos - OS X 上基于 View 的表格单元格未正确显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8353298/