6

I am implementing UIButton and my UIControlEventTouchUpInside event does not fire, even though UIControlEventTouchDown does fire.

UIButton *btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *filePathImage = @"img.png";
NSString *filePathImageTap = @"img-tap.png";
UIImage *buttonImage = [UIImage imageWithContentsOfFile:filePathImage];
UIImage *buttonImageTap = [UIImage imageWithContentsOfFile:filePathImageTap];
[btnClose setImage:buttonImage forState:UIControlStateNormal];
[btnClose setImage:buttonImageTap forState:UIControlStateSelected];
[btnClose setImage:buttonImageTap forState:UIControlStateHighlighted];      
[btnClose addTarget:self action:@selector(close:) forControlEvents:UIControlEventTouchUpInside];    
[self.view addSubview:btnClose];
Coral Doe
  • 1,925
  • 3
  • 19
  • 36
iosdevnyc
  • 1,873
  • 5
  • 25
  • 48
  • Please post the implementation of `-close:`. I suspect that your method doesn't actually take an argument, but by adding the colon in your selector, the wrong message is being sent. – Mark Adams Dec 06 '11 at 18:57
  • Mark it does take an argument, same method work when using UIControlEventTouchDown - (void) close:(id)sender { } – iosdevnyc Dec 06 '11 at 19:40
  • 1
    Where have you specified a target and action for the `UIControlEventTouchDown` control event? – Mark Adams Dec 06 '11 at 19:50
  • I just tried testing by replacing UIControlEventTouchDown instead of UIControlEventTouchUpInside – iosdevnyc Dec 06 '11 at 21:34
  • 9
    Ok Guys, I fixed the issue my stupidity I had UITapGestureRecognizer capturing all the events on the view. I missed it. Sorry and thanks for your help. – iosdevnyc Dec 06 '11 at 22:14
  • 1
    @iosdevnyc you should put this comment as an answer, it helped me. Doing same thing....durrrr moment. – bentford Aug 03 '12 at 20:43
  • 3
    @iosdevnyc: Please post your solution as answer and mark it as accepted in order to help others easier. – Coral Doe Sep 05 '12 at 07:27

1 Answers1

3

I have an assumption why it doesn't take the UIControlEventTouchUpInside:

I had two "BannerView" (Advertisement) in two different ViewControllers. In one it just worked fine in the other I saw how the UIButton was touched and the second image (darker) appeared. But the selector was not hit. Then I realized, that the Up-Event was absorbt by a UISwipeGestureRecognizer from a UIImageView below. Some Recognizer compete against each other. I searched for an overview to see witch ones these are, but found nothing.

Another solution: If you see that the ButtonState doesn't change u have to look if you have a View over your Button.

louis.leon
  • 114
  • 6