nextResponder 响应链

UIView实现了nextResponder

UIView调用nextResponder时,传回它所属的UIViewController,当它没有所属UIViewController时,传回它的superview .

UIViewController实现了nextResponder,  调用nextResponder时,返回它的view的superview.

另外

UIWindow 传回UIApplication对像,  UIApplication 传回 nil (都是指调用nextResponder时)

id next = [self nextResponder];
while(![next isKindOfClass:[ViewController class]]) {
    next = [next nextResponder];
}
if ([next isKindOfClass:[ViewController class]]) {
    controller = (ViewController *)next;
}



你可能感兴趣的:(nextResponder 响应链)