How to call a method inside another method in Objective-C

I am 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 a class method viewDidLoad?

Thank.

+3
source share
4 answers

Just use the "self" object

[self myMethod];

+9
source

Assuming it -viewDidLoadis in the same class, use

[self myMethod];

selfHere is an automatic link to the current instance of the object. If you want to call a method on another object stored in a pointer otherObj, this will be

[otherObj myMethod];
+6
source

, myMethod , viewDidLoad:

- (void)viewDidLoad {
    //...other code
    [self myMethod];
    //...other code
}

Objective-C, Objective-C, :

... or at least read a good primer , for example:
http://www.cocoadevcentral.com/d/learn_objectivec/

There are quite a few useful beginner tutorials by Scott Stephenson here:
http://www.cocoadevcentral.com/

+2
source
[self methodname]; 

will work.

+2
source

All Articles