繁体   English   中英

在xcode中,如何调用返回值的类方法?

[英]In xcode, how to call a class method which returns a value?

我是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];

所以你试图调用一个名为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];

您的方法声明不完整。

更改

+ (UIImage *)burnTextIntoImage:(NSString *)text :(UIImage *)img;

+ (UIImage *)burnTextIntoImage:(NSString *)text img:(UIImage *)img;

您的调用代码错误,请尝试使用此代码

UIImage* image = [PhotoCapViewController burnTextIntoImage:text1 img:imageView.image];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM