StanLe
StanLe

Reputation: 5137

touchesBegan - iPhone app UIView

I have a touchesBegan: method which works fine. However I recently added a UIView (a button) to my UIViewController and now the button isn't registering taps, however my touchesBegan: method is.

How can I tell my touchesBegan: method to avoid the button?

Here is my current touchesBegan: method:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  {
    NSLog(@"touches began");
    UITouch *touch = [touches anyObject];   
    switch ([touch tapCount]) 
    {
        case 1:
            break;

        case 2:
            if(something)
                [doing something];

            break;

        default:
            break;
    }
}

Upvotes: 2

Views: 3247

Answers (2)

Zip184
Zip184

Reputation: 1890

I had the same problem. When I moved my button to the front (in code via UIViewController.bringSubviewToFront) the touchesBegan no longer was fired when I clicked on the button. I'm running Xcode 4.2, in the simulator.

Upvotes: 0

dasdom
dasdom

Reputation: 14063

Make sure that the button is in front ([self.view bringSubviewToFront: myButton]). Then you can ask the touch in which in view it occurred:

if ([touch.view isEqualTo: myButton]) {
    NSLog(@"touch was on button");
}

Upvotes: 1

Related Questions