Nsvaluetransformerclass per nsimage da qualche valore enum / int
-
20-12-2019 - |
Domanda
Come utilizzare una classe trasformabile per legare un NSImageView
in NSTableView
.
C'è una bandiera del tipo enum
, in base a che l'immagine deve essere modificata.
Soluzione
La classe NSValueTransformer
è come:
@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
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow