简体   繁体   中英

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.

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:

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

This shows the IB Name - eg 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. Thanks

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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