首页 > 代码库 > 得到一个view 所在的控制器(viewController)

得到一个view 所在的控制器(viewController)

- (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;

}