代码之家  ›  专栏  ›  技术社区  ›  ICL1901

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

  •  0
  • ICL1901  · 技术社区  · 12 年前

    我有一个NSTableCellView,它有一个简单的NSTextField和一个NSImageCell。

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

    稍后,当我从表中选择一行时,我希望能够看到图像的名称。如果我从IB预加载图像,我可以使用:

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

    这显示IB名称-例如。 NSEveryWhere

    但当我在运行时加载图像时,相同的语句会导致(null)。

    如有任何帮助,将不胜感激。请注意,这是针对OS/X的-但是,为了将来的使用,我也会感谢iOS的想法。谢谢

    1 回复  |  直到 12 年前
        1
  •  1
  •   Aneesh Dangayach    12 年前

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