Question

How to use a transformable class to bind an NSImageView in NSTableView.

There is a flag of type enum, based on that the image needs to be changed.

Was it helpful?

Solution

The NSValueTransformer class is as:

@implementation MyImageTransformer

+ (BOOL) allowsReverseTransformation{
    return NO;
}
+ (Class) transformedValueClass{
    return [NSImage class];
}


- (id) transformedValue:(id)value{

    NSArray *images = @[[NSImage imageNamed:@"failed.png"],
                        [NSImage imageNamed:@"success.png"],
                        [NSImage imageNamed:@"error.png"],
                        [NSImage imageNamed:@"inprogress.png"]
                        ];

    NSInteger integer = [value intValue];

    NSImage * image    = images[integer];
    NSData  * tiffData = [image TIFFRepresentation];

    return tiffData;

}
@end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top