参考链接

In addition to handling events, UIKit responders also manage the forwarding of unhandled events to other parts of your app. If a given responder does not handle an event, it forwards that event to the next event in the responder chain. UIKit manages the responder chain dynamically, using predefined rules to determine which object should be next to receive an event. For example, a view forwards events to its superview, and the root view of a hierarchy forwards events to its view controller.

响应链输出

当前代码位于 UITabBarController 中的一个 UITableViewController 中

1
2
3
4
5
6
UIResponder *responder = self.view;
while(responder)
{
NSLog(@"%@", responder);
responder = [responder nextResponder];
}

UIView -> UIViewController

在不得已需要使 UIView 获取 ViewController 的场景下,可以进行如下操作

1
2
3
4
5
UIResponder *responder = self.view;
while (![responder isKindOfClass:[UIViewController class]] && ![responder isKindOfClass:[UIWindow class]])
{
responder = [responder nextResponder];
}