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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to