响应链的特殊用法
2016-04-17 本文已影响1402人
酷酷的哀殿
Paste_Image.png
//获取某个view所在的控制器
- (UIViewController *)viewController {
UIViewController *viewController = nil;
UIResponder *next = self.nextResponder;
while (next) {
if ([next isKindOfClass:[UIViewController class]]) {
viewController = (UIViewController *)next;
break;
}
next = next.nextResponder;
}
return viewController;
}