写一个UIView的分类,让目的view调用viewController方法即可
@interface UIView (CJSearchVC)
- (UIViewController *)viewController;
@end
@implementation UIView (CJSearchVC)
- (UIViewController *)viewController
{
for (UIView *next = self; next; next = next.superview) {
UIResponder *nextRespoonder = [next nextResponder];
if ([nextRespoonder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextRespoonder;
}
}
return nil;
}
@end