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

标签 objective-c ios xcode

我是 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/

相关文章:

ios - 如何检查 NSDate 是否在特定月份?

ios - 创建新 View 后 iOS 应用程序崩溃

android - iOS 中的 Android okhttp 相当于什么?

objective-c - 在 Xcode 中使用 BLAS 或 LAPACK

ios - "You can’ t 打开应用程序,因为它在这种类型的 Mac 上不受支持。"xcodebuild

ios - Xcode 免费配置 : The 'Apple Push Notification' feature is only available to users enrolled in Apple Developer Program

ios - 是否可以更改 UILabel 中部分文本的背景颜色?如何?

iphone - 如何释放 subview

css - viewport-fit=cover 是否不再适用于 iOS Safari?

java - iOS 日历的 Android 对应物是什么?