简体   繁体   English

NSTableView-如何识别NSTableCellView中图像的名称?

[英]NSTableView - how can I identify the name of the image in an NSTableCellView?

I have a NSTableCellView that has a simple NSTextField and an NSImageCell. 我有一个具有简单的NSTextField和NSImageCell的NSTableCellView。

NSTableCellView *cell = [tableView makeViewWithIdentifier:@"List" owner:self];
cell.textField.stringValue = name;
cell.imageView.image = [NSImage imageNamed:@"image1.png"]; (or image 2,3, etc)

Later, when I select a row from the table, I'd like to be able to see the name of the image. 稍后,当我从表格中选择一行时,我希望能够看到图像的名称。 If I preload the image from IB, I can use: 如果我从IB预加载图像,则可以使用:

NSTableColumn *column = [self.tableView tableColumnWithIdentifier:@"List"];
NSCell *cell = [column dataCellForRow:row];
NSLog(@"TableView image:%@",cell.image.name);

This shows the IB Name - eg NSEveryWhere 这显示IB名称-例如NSEveryWhere

But when I load the images at run time, the same statement results in (null). 但是,当我在运行时加载图像时,相同的语句导致(空)。

Any help would be appreciated. 任何帮助,将不胜感激。 Please note that this is for OS/X - however, for future use, I would appreciate iOS ideas as well. 请注意,这是针对OS / X的-但是,为了将来使用,我也希望iOS的想法。 Thanks 谢谢

我认为您应该使用cell.imageView.image.name而不是记录cell.image.name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM