Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a method from another method in Objective C?

Can someone answer me how to call one method into another in Objective C on Xcode

like image 819
vidhya jain Avatar asked Oct 12 '10 03:10

vidhya jain


3 Answers

The basic syntax for calling a method on an object is this:

[object method]; 
[object methodWithInput:input]; 

If methods returns value:

output = [object methodWithOutput]; 
output = [object methodWithInputAndOutput:input];

More Detail


EDIT:

Here is a good example that how to call method from other class:

OBJECTIVE C - Objective-C call method on another class?

Example:

SomeClass* object = [[SomeClass alloc] init]; // Create an instance of SomeClass
[object someMethod];                          // Send the someMethod message
like image 153
Naveed Avatar answered Oct 19 '22 07:10

Naveed


You get a pointer to an object that implements the other method and send the appropriate message (e.g. [otherObject doSomething]).

like image 5
Chuck Avatar answered Oct 19 '22 07:10

Chuck


For example:

@implementation view1
(void)someMethod
{
   ......code of method...
}

@implementation view2
(void)fistMethod
{
    view1 *abc = [[view1 alloc]init];
    [abc someMethod];
    [abc release];
}

I hope you got it.

like image 4
nlg Avatar answered Oct 19 '22 09:10

nlg