• 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
One IBAction, multiple results from multiple methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

One IBAction, multiple results from multiple methods


  • Subject: One IBAction, multiple results from multiple methods
  • From: Walker Argendeli <email@hidden>
  • Date: Wed, 25 Feb 2009 21:36:10 -0500

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?
I originally used code like this:
- (IBAction)barDoSomething:(id)sender
{...}
- (IBAction)fooDoSomething:(id)sender
{...}
I didn't want a plethora of functions though, so I used code like this, with the object id's coming from IB:
- (IBAction)doSomething:(id)sender
{
if ([sender objectID] == 192])
[foo doSomething];
else if ([sender objectID == 236])
[bar doSomething];
}
There were two problems with this, though. One, there was a lot of repeated code, even without the repeated methods, and 2, it didn't work. (anybody know why? I NSLogged the objectID's and they loged objectID to the console- no number)
What I'd really like is one method that uses the appropriate bar or foo (NSTableViews), and sends to the appropriate array controller, all depending on which button sent the message. I'd have one piece of code, like this:
- (IBAction)doSomething
{
[correctClass doSomething];
}
And appropriate methods/controllers/tableviews/etc. would be used. Any techniques that could be used for this? Maybe using sender? I'm open to Obj-C++ if that's needed, just trying to find a working solution. Also, what would be Obj-C convention for situations like this, if there is no solution, or if I was doing it the traditional way (code snippet 1?)


To summarize:
- What's the traditional way of handling a situation like this?
- Why aren't the objectID's working?
- What solutions are there?

Thanks,
- Walker Argendeli

_______________________________________________

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: Graham Cox <email@hidden>
    • Re: One IBAction, multiple results from multiple methods
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: Observing Managed Object Changes. Was: Strange ... behavior
  • Next by Date: Re: One IBAction, multiple results from multiple methods
  • Previous by thread: Re: Observing Managed Object Changes. Was: Strange ... behavior
  • Next by thread: Re: One IBAction, multiple results from multiple methods
  • Index(es):
    • Date
    • Thread