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:20:33 -0500
On Jan 24, 2010, at 3:10 PM, Andy Lee wrote:
> 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
I thought of another possible motivation Chunk *might* have, which is that he's setting the button's action in code using addTarget:action:forControlEvents: and he wants to use the same action for multiple event types so he doesn't have to call this multiple times. But that doesn't really save any code if you're using a big switch statement in your action method anyway.
Big switch statements are often a red flag that maybe you should be using multiple methods instead -- either different methods within the same class, as in this case, or the same method implemented differently in different subclasses.
--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