Search code examples
objective-cmacoscocoanscell

Flipped NSImage in the NSCell


Why NSImage drawn flipped in the NSCell of NSTableView. And how proper fix that behavior. I returns image from the data source method:

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
return [NSImage imageNamed: @"test.png"];
}

As workaround I tried:

[NSImage setFlipped:NO];

All is ok but as documentation says that it deprecated method

osx 10.7-10.9


Solution

  • I solved problem by replacing code of getting image from:

    return [NSImage imageNamed: @"test.png"];
    

    to:

    NSData * imageData = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForImageResource: test.png]];
    return [[NSImage alloc] initWithDataIgnoringOrientation:imageData];
    

    I don't know reason of that behavior and documentation nothing says me. But I'll happy if you explain me.