Reputation: 99
Can someone answer me how to call one method into another in Objective C on Xcode
Upvotes: 5
Views: 28596
Reputation: 1295
If you have 2 functions inside class(.m file):
-(void) func1{ }
-(void) func2{ }
If you want to call func2 from func1, you cannot just call func2();
instead just include self
That is:
-(void) func1{
[self:func2];
}
Upvotes: 1
Reputation: 161
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.
Upvotes: 4
Reputation: 42093
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];
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
Upvotes: 18
Reputation: 237060
You get a pointer to an object that implements the other method and send the appropriate message (e.g. [otherObject doSomething]
).
Upvotes: 5