我是Objective-C的新手,因为我的生活无法超越错误,“没有选择器的类方法”
这是我的.h代码:
#import <UIKit/UIKit.h>
@interface PhotoCapViewController : UIViewController < UIImagePickerControllerDelegate, UINavigationControllerDelegate > {
UIImageView * imageView;
UIButton * choosePhotoBtn;
UIButton * takePhotoBtn;
}
@property (nonatomic, retain) IBOutlet UIImageView * imageView;
@property (nonatomic, retain) IBOutlet UIButton * choosePhotoBtn;
@property (nonatomic, retain) IBOutlet UIButton * takePhotoBtn;
- (IBAction)getPhoto:(id)sender;
+ (UIImage *)burnTextIntoImage:(NSString *)text :(UIImage *)img;
@end
这是我在.m
中定义的函数+ (UIImage *)burnTextIntoImage:(NSString *)text :(UIImage *)img {
...
return theImage;
}
以下是我如何调用函数
UIImage* image1 = [PhotoCapViewController burnTextIntoImagetext:text1 img:imageView.image];
任何帮助都将不胜感激。感谢。
答案 0 :(得分:7)
您调用的方法与定义不匹配。
定义如下:
+ (UIImage *)burnTextIntoImage:(NSString *)text :(UIImage *)img;
所以方法名是:
burnTextIntoImage::
但你这样称呼它:
UIImage* image1 = [PhotoCapViewController burnTextIntoImagetext:text1 img:imageView.image];
所以你试图调用一个名为this的方法:
burnTextIntoImagetext::
你可以像这样正确地调用它:
UIImage* image1 = [PhotoCapViewController burnTextIntoImage:text1 :imageView.image];
尽管如此,你的方法应该被称为burnText:(NSString*)text intoImage:(UIImage*)image
,所以它更像是一个“句子”,如下所示:
+ (UIImage *)burnText:(NSString *)text intoImage:(UIImage *)image;
...
UIImage *image1 = [PhotoCapViewController burnText:text1 intoImage:imageView.image];
答案 1 :(得分:2)
您的方法声明不完整。
更改
+ (UIImage *)burnTextIntoImage:(NSString *)text :(UIImage *)img;
到
+ (UIImage *)burnTextIntoImage:(NSString *)text img:(UIImage *)img;
答案 2 :(得分:-1)
您的调用代码错误,请尝试使用此代码
UIImage* image = [PhotoCapViewController burnTextIntoImage:text1 img:imageView.image];