views:

254

answers:

3

I have a UISplitViewController setup with a custom view added as a subview of the view (UILayoutContainerView) of split view controller. I am trying to forward touch events from my custom view controller to the master and detail views, but the following (which was suggested here on another thread) seems to have no effect:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{ UITouch *touch = [touches anyObject]; // Do something

[self.nextResponder touchesBegan:touches withEvent:event];

}

(I couldn't get this formatted properly)

As a result my custom view controller locks the events and all the UI underneath never has a chance to do anything.

How can I get my master and detail view controllers to receive events?

Edit: Even if I directly call the 4 touch methods on my detail view controller, the touches aren't properly processed.


A: 

If it's just a subview try to run:

[self.superview touchesBegan:touches withEvent:event];

That should pass it directly to the view above it.

Pyro2927
superview is indeed UILayoutContainerView but both my master and detail view controllers still aren't getting the events.
hyn
A: 

While the Apple documentation says that a UIViewController should be in the that responder chain I've always had issues with getting that call to work. My solution has been to subclass UIView with a -(id) touchDelegate ivar and those methods above. Then just have those methods call up to the delegate. Dirty but it's been working for me.

Here's the official Apple doc if you're interested...

http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html

Staros
my custom view controller actually gets the events; the problem is trying to forward it in a proper manner so that my detail/master views can get the events.
hyn
Without code I can't be specific, but doing something like...- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [otherController touchesBegan: touches withEvent: event];}doesn't seem to work for you?
Staros
A: 

I was able to get the touch events without interfering with the normal event flow by adding a UIGestureRecognizer subclass to the split view controller's view.

From the docs:

UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews.

hyn