How to detect touch end event for UIButton?

cocoa-touch, ios, touch, uibutton

Solution

You can set 'action targets' for your button according to the `ControlEvents`

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

Example:

[yourButton addTarget:self 
           action:@selector(methodTouchDown:)
 forControlEvents:UIControlEventTouchDown];

[yourButton addTarget:self 
           action:@selector(methodTouchUpInside:)
 forControlEvents: UIControlEventTouchUpInside];

-(void)methodTouchDown:(id)sender{

   NSLog(@"TouchDown");
}
-(void)methodTouchUpInside:(id)sender{

  NSLog(@"TouchUpInside");
}

Problem

I want to handle an event occurs when UIButton touch is ended. I know that UIControl has some events implementing touches (UIControlEventTouchDown, UIControlEventTouchCancel, etc.). But I can't catch any of them except UIControlEventTouchDown and UIControlEventTouchUpInside. My button is a subview of some UIView. That UIView has userInteractionEnabled property set to YES. What's wrong?

Original source