2012-08-08 56 views
2

我新的Objective-C和我的生活不能让过去的错误,“为选择无类法”在xcode中,如何调用返回值的类方法?

这里是我的.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

什么问题呢? – 2012-08-08 06:13:42

回答

7

您调用的方法与定义不符。

的定义是这样的:

+ (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]; 
+0

您的最后一段是_truly_正确的答案。其余的只是修补眼前的问题。 – 2012-08-08 06:39:07

+0

同意。顺便说一句,如果你改变了你最喜欢的结,请解决一个SO用户名,否则我完全失去了踪迹。 – jrturton 2012-08-08 06:48:08

+0

已注意。 :)虽然我在这里的大部分时间都是“乔什卡斯韦尔”,但是(这是一个令人吃惊的巧合,也是我在现实生活中使用的名字)。 – 2012-08-08 06:52:00

-1

你拨打代码错误,请尝试使用此代码

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

@CReaTuS:谢谢,但在上面的声明中,它已经完成了** +(UIImage *)burnTextIntoImage:(NSString *)text:(UIImage *)img; ** – Neo 2012-08-08 08:10:23

2

您的方法声明不完整。

变化

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

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

不错的地方,我专注于调用代码不匹配,并错过了缺少的参数名称! – jrturton 2012-08-08 06:30:40

+3

这不是一个参数名称,它是方法名称的一部分。参数名称位于类型的右侧。 – Jesper 2012-08-08 07:53:46

+0

@Jesper当然是,谢谢。早上对我来说很早... – jrturton 2012-08-08 16:31:10

相关问题