Rian Smith
Rian Smith

Reputation: 363

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

I'm new to Objective-C and for the life of me cannot get past the error, "no class method for selector"

Here is my .h code:

#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

Here is the function I have defined in .m

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

    ...

    return theImage;
}

Here is how I'm calling the function

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

Any help would would be appreciated. Thanks.

Upvotes: 2

Views: 9127

Answers (3)

Neo
Neo

Reputation: 2807

Your calling code is wrong, try to use this code

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

Upvotes: -1

jrturton
jrturton

Reputation: 119242

The method you are calling doesn't match the definition.

The definition is this:

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

so the method name is this:

burnTextIntoImage::

But you call it like this:

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

so you're trying to call a method named this:

burnTextIntoImagetext::

You could call it correctly like this:

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

Though really, your method should be called burnText:(NSString*)text intoImage:(UIImage*)image, so it makes more of a "sentence", like this:

+ (UIImage *)burnText:(NSString *)text intoImage:(UIImage *)image;

...

UIImage *image1 = [PhotoCapViewController burnText:text1 intoImage:imageView.image];

Upvotes: 8

Desdenova
Desdenova

Reputation: 5378

Your method declaration is incomplete.

Change

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

to

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

Upvotes: 2

Related Questions