3

In my program, I have a UIButton declared programmatically as a property of a UIVIewController. I have set it up to send actions when the user triggers the touchUpInside event, as shown here:

[restartButton addTarget:self action:@selector(handleRestart) forControlEvents:UIControlEventTouchUpInside]; where restartButton is the name of the UIButton.

When I enter UIControlEventTouchDown in the forControlEvents parameter, it works fine. However, UIControlEventTouchUpInside simply does not work. Does anybody know why this is?

Fitzy
  • 1,871
  • 6
  • 23
  • 40
  • Did you by any chance override `touchesMoved` or `touchesEnded`? – Rok Jarc Jun 10 '12 at 13:50
  • No, but this method is preferable to that if there is a way to make it work. – Fitzy Jun 10 '12 at 13:52
  • You should try to get it working in _normal way_ with `UIControlEventTouchUpInside`. I was just asking because that (overriding) could be the cause. – Rok Jarc Jun 10 '12 at 13:54

2 Answers2

4

Checkout this question and answer: https://stackoverflow.com/a/11667958/607730. The parent view had a UITapGestureReconizer on it that was intercepting the TouchUpInside event but allowing the touch down even through.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
HMCFletch
  • 1,046
  • 1
  • 10
  • 19
3

You may want to check the restartButton.bounds. You may simply have it set to a size of zero causing UIControlEventTouchUpInside never to occur. Best way of checking for it is to add borders to layer.

[restartButton.layer setBorderWidth:1.0f];
[restartButton.layer setBorderColor:[UIColor redColor].CGColor];

Don't forget to #import <QuartzCore/QuartzCore.h> for above to work

Crashalot
  • 33,605
  • 61
  • 269
  • 439
Pierre-Luc Simard
  • 2,723
  • 19
  • 27