@interface UIView(UIViewControllerFinder) - (UIViewController*)viewController; @end @implementation UIView(UIViewControllerFinder) - (UIViewController*)viewController { for (UIView* next = [self superview]; next; next = next.superview) { UIResponder* nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) { return (UIViewController*)nextResponder; } } return nil; } @end
Try this code for find view-controller of view self.btnSubmit (UIButton) or any object inherits from UIView
UIViewController *vc = [self.btnSubmit viewController];
No comments:
Post a Comment