Created
March 16, 2014 14:45
-
-
Save jacklynrose/9584278 to your computer and use it in GitHub Desktop.
Monkey patch for finding the controller of a view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UIView | |
def controller | |
if self.nextResponder.is_a? UIViewController | |
return self.nextResponder | |
elsif self.nextResponder.respond_to? :controller | |
return self.nextResponder.controller | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been using UIViewController.viewControllerForView to accomplish the same thing:
In my app, Ive got a UIView inside a TPKeyboardAvoidingScrollView inside another UIView which is the root view, so I made my function recursive to allow for multiple levels of nesting.