• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: One IBAction, multiple results from multiple methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: One IBAction, multiple results from multiple methods


  • Subject: Re: One IBAction, multiple results from multiple methods
  • From: "I. Savant" <email@hidden>
  • Date: Wed, 25 Feb 2009 21:49:30 -0500

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?

If I read your post correctly, you want one action, called by various controls, and you want to do different thing depending on the sender, right?


For this, we use tags (on the controls). Let's use a concrete example: a media player. You might have a "-seek:" action method. You might have four buttons (seek back, seek back FAST, seek forward, seek forward FAST). Depending on the sending button, you need your media controller to do the right thing.

- (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.

--
I.S.



_______________________________________________

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


  • Follow-Ups:
    • Re: One IBAction, multiple results from multiple methods
      • From: Klaus Backert <email@hidden>
References: 
 >One IBAction, multiple results from multiple methods (From: Walker Argendeli <email@hidden>)

  • Prev by Date: One IBAction, multiple results from multiple methods
  • Next by Date: Re: Select tablecell on creation through arrayController
  • Previous by thread: One IBAction, multiple results from multiple methods
  • Next by thread: Re: One IBAction, multiple results from multiple methods
  • Index(es):
    • Date
    • Thread