Notifying view controller when subview touch events occur.

Posted by Nebs on Stack Overflow See other posts from Stack Overflow or by Nebs
Published on 2010-06-16T19:45:06Z Indexed on 2010/06/16 19:52 UTC
Read the original article Hit count: 661

I have a UIViewController whose view has a custom subview.

This custom subview needs to track touch events and report swipe gestures.

Currently I put touchesBegan, touchesMoved, touchesEnded and touchesCancelled in the subview class. With some extra logic I am able to get swipe gestures and call my handleRightSwipe and handleLeftSwipe methods. So now when I swipe within the subview it calls its local swipe handling methods. This all works fine.

But what I really need is for the handleRightSwipe and handleLeftSwipe methods to be in the view controller. I could leave them in the subview class but then I'd have to bring in all the logic and data as well and that kind of breaks the MVC idea.

So my question is is there a clean way to handle this? Essentially I want to keep my touch event methods in the subview so that they only trigger for that specific view. But I also want the view controller to be informed when these touch events (or in this case swipe gestures) occur.

Any ideas?

Thanks.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk