Search code examples
iosobjective-cuiviewcontrollerswipe-gesture

Add Swipe Gesture to all View controllers in the project


I have set of 50 view controllers with back button. Now I need to add Left to Right swipe gesture for all view controllers in the project. When a swipe is triggered, I need to call back btn clicked event for respective view controller. It is difficult to add swipe gesture to each view controller. Is there any other way to do it with minimal changes to view controllers. Thanks in advance.

Regards, Bharath G


Solution

  • Well these other guys have told you why you may not need to do this, but assuming you do (not using UINavigationController || supporting pre iOs7 ..) then surely the easiest way to add to all of them would be to make a new UIViewController subclass, add the swipeRecogniser in viewDidLoad or similar, and then modify each of your 50 other controllers so that they all inherit from this one (i.e. abstract superclass..)

    I would always have an abstract superclass above UIViewController in a project with 50 or so, obviously there is plenty of code that can be shared