According to a similar question, your method should work.
This leads me to think that your view's nextResponder
is not actually the ViewController
, as you suspect.
I would add a quick NSLog
in your forwarding code to check what your nextResponder
really points to:
if (numTaps < 2) {
NSLog(@"nextResponder = %@", self.nextResponder);
[self.nextResponder touchesBegan:touches withEvent:event];
}
You can also change your other NSLog messages so that they output type and address information:
NSLog(@"touched %@", self);
touched <UIView 0x12345678>
This should get you started on diagnosing the problem.
If I understand correctly, the touchesEnded event is detected, but not by the subview that needs to know about it. I think this might work for you:
In a common file, define TOUCHES_ENDED_IN_SUPERVIEW as @"touches ended in superview".
In the touchesEnded method of the containing view that is firing, add
[[NSNotificationCenter defaultCenter] postNotificationName: TOUCHES_ENDED_IN_SUPERVIEW object: self];
In the touchesBegan of the subviews, add
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(touchesEnded:)
name: TOUCHES_ENDED_IN_SUPERVIEW
object: self.superview];
In the touchesEnded methods of the subviews, use your normal logic for the event, and also add
[[NSNotificationCenter defaultCenter] removeObserver: self name: TOUCHES_ENDED_IN_SUPERVIEW object: self.superview];
Remember to put [[NSNotificationCenter defaultCenter] removeObserver: self] in your dealloc as well, in case it is possible to leave the page without getting the touchesEnded event.
You might want the notification to send its message to a special touchesEndedInSuperview method, which would invoke touchesEnded itself, but that depends on whether you have any special processing to do in that case.
Best Answer