Re: UIButton's Sender Control Events
Re: UIButton's Sender Control Events
- Subject: Re: UIButton's Sender Control Events
- From: Chunk 1978 <email@hidden>
- Date: Sun, 24 Jan 2010 18:22:56 -0500
what i was requesting information about and trying to accomplish was
to simply amalgamate two (or more) methods into one that would be
controlled by one button. so instead of having the following:
- (IBAction)turnLightOn
{
//turn light on
}
- (IBAction)turnLightOFF
{
//turn light off
}
i wanted to simplify the code (one button per method) by using the
buttons UIControlEvents of touchDown and touchUpInside/touchUpOutside
and produce:
- (IBAction)toggleLight
{
//toggle light
}
it's clear now that it's not possible.
On Sun, Jan 24, 2010 at 6:12 PM, Chunk 1978 <email@hidden> wrote:
> so it's considered better to have the following:
>
> - (IBAction)button1
> {
> //button 1 action
> }
>
> - (IBAction)button2
> {
> //button 2 action
> }
>
> - (IBAction)button3
> {
> //button 3 action
> }
> .
>
> than to have the following:
>
> - (IBAction)buttons:(id)sender
> {
> switch ([sender tag])
> case 1: //button 1 action; break;
> case 2: //button 2 action; break;
> case 3: //button 3 action; break;
> }
>
> i would find it hard to believe that the former solution is both
> easier to debug and maintain than the later.
>
>
> On Sun, Jan 24, 2010 at 5:06 PM, Graham Cox <email@hidden> wrote:
>>
>> On 25/01/2010, at 5: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, not really. This is object-oriented programming, having separate methods is effectively just moving the if/else (or switch) back into the runtime. There's little need to also do it yourself.
>>
>> --Graham
>>
>>
>
_______________________________________________
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