//获取View的ViewController
- (UIViewController )viewController {
//便利
for (UIView next = [self superview]; next; next = next.superview) {
//响应者链
UIResponder *nextResponder = [next nextResponder];
//判断View所述的ViewController
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
原理:
通过 便利 响应者链 判断 是否是该 View 的VIewControll