Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,215
1,029
I want to return to a function after another completes, how do I do this?
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
I want to return to a function after another completes, how do I do this?

If you call one function from inside another, the program returns to the first ("outer") function after the 2nd ("inner") function completes.

So if you have
Code:
int outer() {

   int x = 0;
   inner();
   x = x + 1;
   return x;
}

The program will run inner() and then go back to outer() and return 1.
 

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,215
1,029
I think I may have asked the question wrong...or worded it wrong.

I have multiple IBActions, each can be called on its own, but after it is called it effects other IBActions. I want to have an IBAction call on another IBAction after it completes its execution.

Something like...

Code:
-(IBAction)run {
     do stuff
     reselect action
     start (IBAction)doSomeThingElse
}
 

MacDonaldsd

macrumors 65816
Sep 8, 2005
1,005
0
London , UK
I think I may have asked the question wrong...or worded it wrong.

I have multiple IBActions, each can be called on its own, but after it is called it effects other IBActions. I want to have an IBAction call on another IBAction after it completes its execution.

Something like...

Code:
-(IBAction)run {
     do stuff
     reselect action
     start (IBAction)doSomeThingElse
}

This will do it.

Code:
-(IBAction)theFirstFunction:(id)sender{

[self theSecondFunction:self];
}

-(IBAction)theSecondFunction:(id)sender{
//Whatever
}
 

kalimba

macrumors regular
Jun 10, 2008
102
0
This will do it.

Code:
-(IBAction)theFirstFunction:(id)sender{

[self theSecondFunction:self];
}

-(IBAction)theSecondFunction:(id)sender{
//Whatever
}

Will that do what the OP wants? Keep in mind that I'm pretty new to Cocoa/Obj-C, but would the following snippet be the proper way to chain to a second function, and if not, why not?

Code:
-(IBAction)theFirstFunction:(id)sender{

[self theSecondFunction:[B][COLOR="Red"]sender[/COLOR][/B]];
}

-(IBAction)theSecondFunction:(id)sender{
//Whatever
}
 

SqueegyX

macrumors regular
Mar 24, 2008
108
1
Will that do what the OP wants? Keep in mind that I'm pretty new to Cocoa/Obj-C, but would the following snippet be the proper way to chain to a second function, and if not, why not?

Code:
-(IBAction)theFirstFunction:(id)sender{

[self theSecondFunction:[B][COLOR="Red"]sender[/COLOR][/B]];
}

-(IBAction)theSecondFunction:(id)sender{
//Whatever
}

I was thinking the same thing. Although the sender argument is rarely used (in my experience at least), and it is of type id so it could be any object (or nil). So you could probably pass whatever you want to it unless your app depends on its value, usually when multiple buttons are linked to the same action and you need to detect which one got hit.

But yeah this is probably the "more right" way to do it:

Code:
[self theSecondFunction:[B][COLOR="Red"]sender[/COLOR][/B]]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.