Re: UIButton's Sender Control Events
Re: UIButton's Sender Control Events
- Subject: Re: UIButton's Sender Control Events
- From: Andy Lee <email@hidden>
- Date: Sun, 24 Jan 2010 15:10:28 -0500
On Jan 24, 2010, at 2:48 PM, mmalc Crawford wrote:
> On Jan 24, 2010, at 10:27 am, Chunk 1978 wrote:
>
>> refactoring code so one method for the same button can handle a small
>> if/else statement could easily be considered more ideal than having
>> two separate methods.
>>
> No, it couldn't. If you have different actions that should happen in response to different control events, then the trivial thing to do is to implement different methods for each.
And if the actions all look very similar, you could have all the different methods call a common method like
- (void)handleMyButtonEvent:(int)eventType
{
...
}
- (IBAction)myButtonTouchDown:(id)sender
{
[self handleMyButtonEvent: ...];
}
- (IBAction)myButtonTouchUp:(id)sender
{
[self handleMyButtonEvent: ...];
}
But I'd need some idea of what your action method(s) look like to make any further suggestion about refactoring.
>> at this point i'm wondering if it's even possible.
If by "it" you mean knowing what kind of event triggered the button action when you use the same action for all of a button's event types... I looked in the iPhone SDK docs and offhand didn't see an equivalent for [NSApplication currentEvent], but note I'm not an iPhone expert. Maybe it's possible to create a UIApplication subclass that provides such a method. Personally, I would use the different action methods, and use the fact that a particular action was called to tell you which type of event triggered it, since that's how the framework is designed to be used.
--Andy
_______________________________________________
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