官方解释
UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t); UIViewController implements the method by returning its view’s superview; UIWindow returns the application object, and UIApplication returns nil.
id next = [self nextResponder];
while(![next isKindOfClass:[ViewController class]]) {
next = [next nextResponder];
}
if ([next isKindOfClass:[ViewController class]]) {
controller = (ViewController *)next;
}转载于:https://blog.51cto.com/lych0317/1214728
本文解析了UIKit中响应链的工作原理,详细介绍了UIView、UIViewController、UIWindow等类如何通过nextResponder属性确定响应者,并最终找到对应的ViewController来处理事件。
765

被折叠的 条评论
为什么被折叠?



