Reputation: 83
I'm new to Objective-C.
If I wrote this method declaration in .h
-(void)myMethod;
and this implementation in .m
-(void)myMethod{
NSLog(@"This is myMethod");
}
How can I call it in my class' viewDidLoad
method?
Thank you.
Upvotes: 4
Views: 8116
Reputation: 29552
Assuming that you're calling myMethod
on the same class as what implements viewDidLoad
:
- (void)viewDidLoad {
//...other code
[self myMethod];
//...other code
}
If you are having trouble with basic Objective-C though, I'd strongly suggest to either get a decent book on Objective-C, such as:
…or at least read a good beginners tutorial, such as:
http://www.cocoadevcentral.com/d/learn_objectivec/
There are quite a few more helpful beginners tutorials by Scott Stevenson here:
http://www.cocoadevcentral.com/
Upvotes: 2
Reputation: 17906
Assuming that -viewDidLoad
is in the same class, use
[self myMethod];
self
here is an automatic reference to the current object instance. If you want to call a method on another object stored in a pointer otherObj
, it would be
[otherObj myMethod];
Upvotes: 7