ManojRupareliya
ManojRupareliya

Reputation: 21

Xcode for How to call function from one class to another class function in iPhone Apps

JewelsSharedController.m:

-(void)GetCountries:(id)sender detailDictionary:(id)details
{
}

and I want to call this function in RootViewController's function like
RootController.m:

-(void)soapresult
{
    //i want to call ""GetContries "" here..
}

and i m call this "soapresult" in to

-(void)viewdidLoad
{
    [self soapresult];
}

but when calling function its crash

Upvotes: 0

Views: 8826

Answers (2)

Kjuly
Kjuly

Reputation: 35141

JewelsSharedController.h:

//...
-(void)GetCountries:(id)sender detailDictionary:(id)details;
//...

RootController.m:

#import "JewelsSharedController.h"

//...

-(void)soapresult
{
    JewelsSharedController * jewelsSharedController = [[JewelsSharedController alloc] init];
    [jewelsSharedController GetCountries:yourSender detailDictionary:yourDetails];
    [jewelsSharedController release];
}

Upvotes: 2

Armand
Armand

Reputation: 10264

Change this

-(void)GetCountries:(id)sender detailDictionary:(id)details

{

}

To

+(void)GetCountries:(id)sender detailDictionary:(id)details

{

}

And then to call it in another class simply do

[JewelsSharedController GetCountries];

What we are doing is creating a class function, what that means is you can call the function directly on the class without having to initialize an instance of the class first.

Upvotes: 0

Related Questions