- (UIViewController *)viewController{
for (UIView* next = self; next; next = next.superview) {
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController*)nextResponder;
}
}
return nil;
}
也可以根据这个方法找到想要的父视图