objective-ciosuibuttonhuman-interfaceuicontrolevents

UIButton not responding to 'touchUpInside' but will respond to 'touchDown' fine


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?


Solution

  • 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