iosobjective-cuibuttonobserver-patternuicontrolevents

How do I add observer to UIButton?


I want be signaled when user will touch button (UIControlEventTouchUpInside). How do I add observer to UIButton?


Solution

  • Look at the documentation of UIControl.

    [myButton addTarget:self 
                 action:@selector(touch:) 
       forControlEvents:UIControlEventTouchUpInside];
    

    This method works for anything that inherits from UIControl (including but not limited to UIButtons :)