• 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: Dave DeLong <email@hidden>
  • Date: Thu, 26 Feb 2009 09:20:42 -0700

Here's one for you:

I created a small app for the purpose of testing how to post CGEvents and ended up building a keyboard in a window out of a whole bunch of NSButtons. I didn't want to wire up each button to a separate IBAction, because that would've been about 100 IBActions all doing the same thing (the only difference being which keycode to dispatch). So I created one IBAction, then hardcoded the keycode as the tag of each button.

It would've been REALLY nice to put something like the following into my .h file and have IB autodiscover it:

#define IBTag KEYCODE_A 0
#define IBTag KEYCODE_Z 6
...etc

And then have the tag field autocomplete those in IB. I think anyone who would later look at my code would understand a heck of a lot better what's going on. Yes, it's theoretically more work (to do both the #defines and the tag hardcoding), but when you look at a button in IB and see a tag of "42", I don't know anyone who thinks "aha, that's a backslash". But if it were "KEYCODE_BACKSLASH_PIPE", that would make a whole lot more sense. =)

Dave

On Feb 26, 2009, at 9:11 AM, I. Savant wrote:

On Thu, Feb 26, 2009 at 10:53 AM, Michael Ash <email@hidden> wrote:

It's true that there are scenarios where dispatching off the tags are
helpful, but I don't think that this is one of them.

You're absolutely right, it's a stretch to use this example because it's not complicated enough to highlight the point I'm making. Laziness is my only excuse for not providing a more complex example. :-)
_______________________________________________

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: Andy Lee <email@hidden>
    • Re: One IBAction, multiple results from multiple methods
      • From: "Paul Sanders" <email@hidden>
    • Re: One IBAction, multiple results from multiple methods
      • From: "I. Savant" <email@hidden>
References: 
 >One IBAction, multiple results from multiple methods (From: Walker Argendeli <email@hidden>)
 >Re: One IBAction, multiple results from multiple methods (From: "I. Savant" <email@hidden>)
 >Re: One IBAction, multiple results from multiple methods (From: Klaus Backert <email@hidden>)
 >Re: One IBAction, multiple results from multiple methods (From: "I. Savant" <email@hidden>)
 >Re: One IBAction, multiple results from multiple methods (From: Michael Ash <email@hidden>)
 >Re: One IBAction, multiple results from multiple methods (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: NSTableView && Custom Background ...
  • Next by Date: Re: One IBAction, multiple results from multiple methods
  • Previous by thread: Re: One IBAction, multiple results from multiple methods
  • Next by thread: Re: One IBAction, multiple results from multiple methods
  • Index(es):
    • Date
    • Thread