开发者

unrecognized selector

开发者 https://www.devze.com 2023-03-30 08:14 出处:网络
I have a problem with the next code: NSDictionary * imagen = [[NSDictionary alloc] initWithDictionary:[envio resultValue]];

I have a problem with the next code:

NSDictionary * imagen = [[NSDictionary alloc] initWithDictionary:[envio resultValue]];
NSString *imagenS = [imagen valueForKey:@"/Result"];

ClaseMaestra *b1 = [[ClaseMaestra alloc]init];
NSData *imagenDecode = [[NSData alloc] initWithData:[b1 base64DataFromString:imagenS]];

NSLog(@"Decode Image:");
NSLog(@"%@", imagenDecode);

//SAVE IMAGE

NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  

NSString *docDirectory = [sysPaths objectAtIndex:0]; 

NSString *filePath = [NSString stringWithFormat:@"%@david.png",docDirectory]; 开发者_运维技巧

[imagenDecode writeToFile:filePath atomically:YES]; 

Blockquote

[envio resultValue] --> return a NSDictionary with one image in Base 64 codification.

I want decoder and save this image but in my console I have showed this message:

2011-08-23 19:19:39.750 WSStub[38501:a0f] *************************
2011-08-23 19:19:39.752 WSStub[38501:a0f] SendImage
2011-08-23 19:19:39.752 WSStub[38501:a0f] *************************
2011-08-23 19:19:39.759 WSStub[38501:a0f] -[ClaseMaestra base64DataFromString:]: unrecognized selector sent to instance 0xd00ad0
Program received signal:  “EXC_BAD_ACCESS”.

ClaseMaestra interface is:

#import <Foundation/Foundation.h>

@class NSString;

@interface ClaseMaestra : NSObject 

+ (NSMutableData *)base64DataFromString: (NSString *)string;

@end

I can´t understand the "unrecognized selector" error...


This is a class method and you call iton an instance of the class. You should either change it to an instance method. instead of:

+ (NSMutableData *)base64DataFromString: (NSString *)string;

Use:

- (NSMutableData *)base64DataFromString: (NSString *)string;

Or, change the call, instead of:

NSData *imagenDecode = [[NSData alloc] initWithData:[b1 base64DataFromString:imagenS]];

Use:

NSData *imagenDecode = [[NSData alloc] initWithData:[ClaseMaestra base64DataFromString:imagenS]];

What to choose depends on your needs.


base64DataFromString: is a class method (starts with a +). So instead of

ClaseMaestra *b1 = [[ClaseMaestra alloc]init];
NSData *imagenDecode = [[NSData alloc] initWithData:[b1 base64DataFromString:imagenS]];

You should do

NSData *data = [ClaseMaestra base64DataFromString:imagenS];


You are sending a class message to an instance. The receiver should be a class.

So do:

NSData *imagenDecode = [[NSData alloc] initWithData:[ClaseMaestra base64DataFromString:imagenS]];


You'll also get this error if you use the name of a private framework, eg: MPMovieView .Everyone knows you're not supposed to use those, but what I didn't know is that I was using one!

What's odd is, if you use Xibs, they load the system one and give you the same type of error (Class methods).

But if you load it in code, it shadows the system framework one. I spent a decent hour scratching my head, ensuring everything was hooked up right... it was, just needed to change how I named my custom stuff. Posting this for anyone with similar

0

精彩评论

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