One option is to set the button up using
[MyButton addtarget:yourotherclass Action: @selector (Myselector:) forcontrolevents:uicontroleventtouchupinside];
It is a bit dangerous because are not retained so you target could send the message to a Deallocated object.
You could instead set up a protocol
MyController.h
@protocol mycontrollerdelegate-(void) Mycontroller: (Mycontroller *) controller buttontapped: (UIButton * ) button; @end @interface IDdelegate; -(Ibaction) buttontapped: (UIButton *) button; @end
Then in your implementation
MyController.m
-(Ibaction) buttontapped: (UIButton *) button{ if ([self]. Delegate respondstoselector: @selector (mycontroller:buttontapped:)]) { [self. Delegate mycontroller:self Buttontapped:button];} }
As the method defined in the protocol be not optional I could has instead do a check for to make (self.delegate) sure it is set Instead of respondsToSelector .
UIButton set Touch Handler in code