jake9115
jake9115

Reputation: 4084

Can't call a method with another method, what am I missing?

Extremely basic objective-c question here. I want to call a method from within another method and send a variable from the first method to the second method, but I'm not sure how to handle this with @implementation, etc.

Here is what I want:

-(int) isItFav:(int) favNum
{
 // some code   
}

- (IBAction)myBar:(UISegmentedControl *)sender
{
 // some code
 int x = 10;
 [isItFav x];
}

This causes as error, as isItFav is an undeclared identifier. Can someone please tell me how to fix this up?

Upvotes: 0

Views: 58

Answers (3)

Kiattisak Anoochitarom
Kiattisak Anoochitarom

Reputation: 2157

Message Call Format is

[sender message:params]

Upvotes: 0

Anoop Vaidya
Anoop Vaidya

Reputation: 46543

If both myBar: and isItFav: are in same class:

int returnedValue = [self isItFav:x];

If in different class, then

int returnedValue = [objectOfClassWhichContainsIsItFavMethod isItFav:x];

This is Objective-C. Please see tutorials and manuals.

Upvotes: 2

William Falcon
William Falcon

Reputation: 9813

[receiverOfCall method:param];

This case: int result = [self isItFav:x];

Upvotes: 0

Related Questions