instance method of class for iphone
i want to create some header file for future use but i have 1 problem
i have defined a method in lets say Rimage class called check1 now i want to call that from maiviewcont
so i did this in mainVC.h i defined a instance of Rimage class
#import <UIKit/UIKit.h>
@class Rimage;
@interface Rahul_imageplaceCordinatesViewController : UIViewController {
Rimage *aRimage;
}
@property (nonatomic,copy) Rimage *aRimage;
@end
and in .m
[self.aRimage check1];
aRimage = [Rimage check1];
but both are not workin开发者_C百科g
i went for both +(void)check1 and -(void)check1 in Rimage class
The two examples you give do very different things:
[self.aRimage check1];
invokes an check1
instance method on aRimage
.
aRimage = [Rimage check1];
calls the check1
class method on the Rimage
class, and assigns the result to aRimage
.
In both cases, you will need to #import "Rimage.h
in your .m file, else you'll get warnings like "aRimage may not respond to 'check1'".
EDIT
Your ".h" file is declaring a property named "aRimage", but that value will be nil until you assign something to it, by doing something like:
self.aRimage = [[[Rimage alloc] init] autorelease];
See this question for a good explanation of the difference between class methods and instance methods.
ps. and don't forget to do a [aRimage release]
in your dealloc method
精彩评论