我是 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];
如有任何帮助,我们将不胜感激。谢谢。
最佳答案
您调用的方法与定义不匹配。
定义是这样的:
+ (UIImage *)burnTextIntoImage:(NSString *)text :(UIImage *)img;
所以方法名是这样的:
burnTextIntoImage::
但是你这样调用它:
UIImage* image1 = [PhotoCapViewController burnTextIntoImagetext:text1 img:imageView.image];
所以你试图调用一个名为这个的方法:
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];
关于objective-c - 在 xcode 中,如何调用返回值的类方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11858628/