iPhone:“'class_name'可能无法响应”methd_name“和”无法识别的选择器“错误

时间:2010-03-03 11:26:13

标签: iphone cocoa-touch uiimage selector

我已经编写了一个应用程序,我想将.jpg图像转换为.bmp格式,但我失败并出现错误:

  

class_name'可能无法响应   methd_name”。

我的代码如下:

#import "CalculateRGBViewController.h"

@implementation CalculateRGBViewController

@synthesize skinImage;
@synthesize lblRedColor,btn,img;
struct pixel {
    unsigned char r, g, b,a;
};


-(IBAction)btnClick:(id) sender{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];

}
-(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [picker dismissModalViewControllerAnimated:YES];
    skinImage.  image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

}

+(void)calculateRGB:(UIImage *)skinImage    {

    struct pixel *pixels = (struct pixel *) calloc(1, skinImage.size.width * skinImage.size.height * sizeof(struct pixel));
    if (pixels != nil)
    {
        // Create a new bitmap

        CGContextRef context = CGBitmapContextCreate(
                                                     (void*) pixels,
                                                     skinImage.size.width,
                                                     skinImage.size.height,
                                                     8,
                                                     skinImage.size.width * 4,
                                                     CGImageGetColorSpace(skinImage.CGImage),
                                                     kCGImageAlphaPremultipliedLast
                                                     );
    NSLog( @"Pixel data one red (%i)", context);        
}

}
-(IBAction)btnCalRGB:(id) sender
{
    [self calculateRGB];

}

The shown me following code. 
-(IBAction)btnCalRGB:(id) sender
{
    [self calculateRGB];


}

警告:在btnCalRGB按钮功能中,CalculateRGBController可能无法响应calculateRGB。

Edit01:

我也在我的代码中实现了但它再次显示相同的警告。

[self calculateRGB:anUIImage]; 
-(IBAction)btnCalRGB:(id) sender; 

但它再次显示相同的警告。按下上面的按钮时,程序抛出异常。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[UIImage skinImage]: unrecognized selector sent to

2 个答案:

答案 0 :(得分:1)

您调用方法错误。你必须这样称呼它;

[self calculateRGB:anUIImage];

您的方法将UIImage作为参数,因此您必须在调用方法时发送它。你还应该添加

+(void)calculateRGB:(UIImage *)skinImage;

到你的.h文件

使用此

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { 

而不是

-(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

你可以写

skinImage.image = image;

答案 1 :(得分:0)

首先,要摆脱错误:

+(void)calculateRGB:(UIImage *)skinImage

应该是

- (void)calculateRGB:(UIImage *)skinImage

+用于方法,您即将在实例上调用此方法(我们需要使用- })。因此,错误是因为您尝试调用实例方法,但没有名为calculateRGB:的实例方法。

该方法需要UIImage进行计算。这意味着你应该打电话给它(就像EEE告诉你的那样):

[self calculateRGB:anImage];

anImage将是您提供的UIImage个实例。这可能是您已在实施中使用的skinImage,如代码中所示。

除此之外,我建议使用UIViewController子类来计算图像的RGB值。您可能应该使用UIImage类别。