I created a UIView
subview which I add to my UIViewController
in storyboard, I want to respond to a tap on the subview and call the superview's implementation of the following method. The call works properly, but it doesn't pass as an argument the proper touch.tapcount
to the superview's implementation.
Here is the method in the subview:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
CGRect rect = [[UIScreen mainScreen] bounds];
UITouch *touch = [[event touchesForView:self]anyObject];
CGPoint location = [touch locationInView:self];
if(touch.tapCount == 2){
[self.superview touchesBegan:touches withEvent:event];
}
}
Here is the method in the superview, the if block is not executed:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
CGRect rect = [[UIScreen mainScreen] bounds];
UITouch *touch = [[event touchesForView:self]anyObject];
CGPoint location = [touch locationInView:self];
if(touch.tapCount == 2){
//Code is not executed here
}
}
Solution
change this statement in superview:
UITouch *touch = [[event touchesForView:self]anyObject];
to this:
UITouch *touch = [[event touchesForView:[self.view.subviews objectAtIndex:1]] anyObject];