Re: One IBAction, multiple results from multiple methods
Re: One IBAction, multiple results from multiple methods
- Subject: Re: One IBAction, multiple results from multiple methods
- From: Klaus Backert <email@hidden>
- Date: Thu, 26 Feb 2009 10:39:44 +0100
On 26. Feb 2009, at 03:49, I. Savant wrote:
On Feb 25, 2009, at 9:36 PM, Walker Argendeli wrote:
Lets say I have some custom code that does the same thing, with the
exception that a few IBOutlets are different for each type.
Instead of having multiple methods, is there a way to use 1
IBAction, and take necessary action depending on where it was sent?
<snip>
- (IBAction)seek:(id)sender
{
int tag = [sender tag]; // or NSInteger tag = [sender tag];
switch (case)
{
case 1001: // seek back
[self seekBack];
break;
case 1002: // seek back FAST
[self seekBackFast];
break;
case 1003: // seek forward
[self seekForward];
break;
case 1004: // seek forward FAST
[self seekForwardFast];
break;
default:
NSBeep(); // don't know what to do here ...
break;
}
}
Don't forget to set the tags in IB for your controls.
... and now we went from a plethora of methods to the same plethora of
case statements plus tags.
For the methods the dispatch is made under the hood. The switch
statement is kind of re-inventing the objected-oriented wheel in a
procedural way.
Klaus
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden