找到一个view所在的controller其实 就是顺着他的响应链一直往下找,直到找到一个responser类型是UIViewController。
-(UIViewController*)findViewControllerOfView:(UIView*)viewA{
id responser = viewA.nextResponder;
UIViewController* resultController = [[UIViewController alloc] init];
while (![responser isKindOfClass:[UIViewController class]]) {
responser = [responser nextResponder];
}
if ([responser isKindOfClass:[UIViewController class]]) {
resultController = responser;
}
return resultController;
}
网友评论