建议写成UIView的分类,如下:
.h
- (UIViewController *)viewController;
.m
- (UIViewController *)viewController { UIResponder *responder = self.nextResponder; while (![responder isKindOfClass:[UIViewController class]] && responder != nil) { responder = responder.nextResponder; } return (UIViewController *)responder;}