iosuigesturerecognizerresponder-chain

IBAction does not fire when I add viewDidLoad


I have several IBActions attached to UIButtons. The IBActions work fine until I add the following code:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"View Did Load");
    [self addGestureRecognizersToView:drawImage];
}

After I add that chunk of code the IBActions do not fire. The UIButtons highlight when I touch them, but none of the IBAction code gets hit.

Here is my addGestureRecognizers code:

- (void)addGestureRecognizersToView:(UIImageView *)theView {
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
    [panGesture setMaximumNumberOfTouches:2];
    [panGesture setMinimumNumberOfTouches:1];
    //panGesture.delegate = drawImage;
    [theView addGestureRecognizer:panGesture];
    [panGesture release];

    UITapGestureRecognizer *doubleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
    [doubleFingerTap setNumberOfTapsRequired:2];
    [self.view addGestureRecognizer:doubleFingerTap];
    [doubleFingerTap release];

    UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    [singleFingerTap setNumberOfTapsRequired:1];
    [self.view addGestureRecognizer:singleFingerTap];
    [singleFingerTap release];
}

If I comment out the singleFingerTap code it works. I'm guessing I should not be using alloc since I have already alloced that once before in doubleFingerTap?

Any ideas on what I might be missing here?


Solution

  • You single finger tap is hindering with the normal behavior of the button. You will have to make sure the touches get through unhindered.

    [singleFingerTap setCancelsTouchesInView:NO];