1

In my cocoa app there is a NSTableView(10.7 lion view based tableview) only contains one column, the cell in it is a custom NSTableCellView, in it there are several views and one of them is a NSImageView.

My data model has an integer status variable, I use cocoa binding and a NSValueTransformer to give different NSImage to this NSImageView.

The problem is, the image is not updated automatically. After the status is changed, the image only reflects the change after reload the list.

Thanks for any help :)

kcome
  • 1,166
  • 9
  • 22
  • I found actually the NSImageView will change after my integer status property get changed, however that takes almost 10 seconds after the change happened. If I use KVO instead of bind in the interface builder, that delay is the same. – kcome Oct 07 '11 at 02:18

1 Answers1

0

Finally I solved my own question.

I added observer for model's "status" integer property. When this status changed, the actual table cell's icon (NSImageView) has changed according to the cocoa binding but not updated. Then in the observe callback method, just add

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
Model *m = (Model*)context;
NSInteger idx = [self.modelArray indexOfObject:m];
NSTableRowView *row = [self.tableView rowViewAtRow:idx makeIfNecessary:NO];
ListCellItem *cell = [row viewAtColumn:0];
cell.icon.needsDisplay = YES;
[cell.icon.image recache];
[cell.icon display];
}

Then the image get updated as soon as status get changed.

kcome
  • 1,166
  • 9
  • 22