Search code examples
iphoneobjective-ciphone-sdk-3.0uibuttoncocoa-design-patterns

How to add (id) sender to the following -(IBAction)?


How do you add a (id) sender to the following code?

- (IBAction) gobutton: (UIButton *) button5 {

Everything I try fails, any help would be appreciated. Thanks.

EDIT: I need to keep the (UIButton *) button 5 reference in the (IBAction)


Solution

  • If I recall correctly, and if you are using this in the way I think you are,

    - (IBAction) gobutton: (id) sender {
    if(sender == button5)
       //do something...
    else
       //do something else...
    }
    

    Assuming that you specified button5 as a parameter to indicate that this executes in response to button5 being pressed.