省钱达人

UIView+ViewController.m 708B

12345678910111213141516171819202122232425262728
  1. //
  2. // UIView+ViewController.m
  3. // MLMSegmentPage
  4. //
  5. // Created by MAC on 2017/5/18.
  6. // Copyright © 2017年 my. All rights reserved.
  7. //
  8. #import "UIView+ViewController.h"
  9. @implementation UIView (ViewController)
  10. - (UIViewController *)viewController {
  11. UIResponder *next = self.nextResponder;
  12. do {
  13. if ([next isKindOfClass:[UIViewController class]]) {
  14. return (UIViewController *)next;
  15. } else if ([next isKindOfClass:[UINavigationController class]]) {
  16. UINavigationController *nav = (UINavigationController *)next;
  17. return nav.viewControllers.lastObject;
  18. }
  19. next = next.nextResponder;
  20. }while (next != nil);
  21. return nil;
  22. }
  23. @end