开发者

[NSConcreteData scale]: unrecognized selector sent to instance when accessing an image property

I've a problem when I try to access the image property of one Core Data Model:

#import <CoreData/CoreData.h>

@class IngredientWithQuantity;

@interface Cocktail :  NSManagedObject  
{
}

@property (nonatomic, retain) UIImage *image;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * desc;
@property (nonatomic, retain) NSSet* ingredients;

@end


@interface Cocktail (CoreDataGeneratedAccessors)
- (void)addIngredientsObject:(IngredientWithQuantity *)value;
- (void)removeIngredientsObject:(IngredientWithQuantity *)value;
- (void)addIngredients:(NSSet *)value;
- (void)removeIngredients:(NSSet *)value;

@end

The image is set as a Transformable

#import <UIKit/UIKit.h> 


@interface ImageToDataTransformer : NSValueTransformer {

}

@end

Implementation

#开发者_开发百科import "ImageToDataTransformer.h"

@implementation ImageToDataTransformer


+ (BOOL)allowsReverseTransformation {
    return YES;
}

+ (Class)transformedValueClass {
    return [NSData class];
}


- (id)transformedValue:(id)value  {
    if (value == nil) {
        return nil;
    }

    // I pass in raw data when generating the image, save that directly to the database
    if ([value isKindOfClass:[NSData class]]) {
        return value;
    }

    return UIImagePNGRepresentation((UIImage *)value);
}


- (id)reverseTransformedValue:(id)value {
    return [UIImage imageWithData:(NSData *)value];
}

@end

When I set the image it seems work fine but when I try to use it inside a view, with this code:

- (void)viewDidLoad {
    [super viewDidLoad];    

    self.title = cocktail.name; //works

    self.descriptionView.text = cocktail.desc; //works

    pictureView.image = cocktail.image; //crash
}

i get this error:

2010-10-12 17:22:25.409 PrimosBar[2399:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteData scale]: unrecognized selector sent to instance 0xc027e00'

And I don't know how to resolve :(

Can you help me?

Thanks :)


If I read NSConcreteData I think you are not saving an UIImage to your ManagedObject but an "pure" image, ie jpg, png etc.

Make sure you create an UIImage out of your pure data first. Maybe you want to post the code where you assign the image to the managed object.


To me it looks like you don't have an UIImage there at that point in time but something else. This can be because your cocktail.image is somehow already released.

However, I never used Core Data so far, so I might be totally off :-) (BTW, are you sure that what you have there is actually an UIImage?).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜