UIView nextResponder如何知道UIViewController是什么? [英] How does UIView nextResponder know what the UIViewController is?

查看:182
本文介绍了UIView nextResponder如何知道UIViewController是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像好奇心一样,UIView类的nextResponder方法实现如何知道谁是UIViewController来管理视图?
UIResponder文档说明了这一点,我可以看到它的工作,但我不太理解它。据我所知,一个UIView不保持对它的控制器的引用,那么幕后发生了什么?或者我只是缺少一些明显的东西?

Just as a matter of curiosity, how does the nextResponder method implementation of the UIView class know who is the UIViewController that manages the view? The UIResponder documentation states this, and I can see it work, but I don't quite understand it. To the best of my knowledge, a UIView does not maintain a reference to it's controller, so what's happening behind the scenes? Or am I just missing something obvious?

我还是非常新的Objective-C和iPhone开发,所以我道歉,如果这是明显的,但我很好奇。

I'm still very new to Objective-C and iPhone development so I apologize if this is something obvious, but I am quite curious.

谢谢!

推荐答案

响应者链与视图层次结构分离。响应者链可能如下所示:

The responder chain is separate from the view hierarchy. The responder chain might look like this:

First Responder > View Hierarchy > Window > Window Delegate > etc...

然而,对象可以将自己插入响应链,这就是UIViewController。从文档:

However, objects can insert themselves into the responder chain and that's what UIViewController does. From the docs:


由于视图控制器与其管理的视图紧密绑定,因此它们也是用于处理事件的响应链。视图控制器本身是UIResponder类的后代,并插入到受管视图和其超级视图之间的响应链中。

Because view controllers are tightly bound to the views they manage, they are also part of the responder chain used to handle events. View controllers are themselves descendants of the UIResponder class and are inserted into the responder chain between the managed view and its superview.

,这是使用-setNextResponder:方法实现的。该方法在Cocoa Touch中不是公开的,但是这就是UIViewController看起来做的事。

In Big Cocoa, this is accomplished using the -setNextResponder: method. That method isn't public in Cocoa Touch, but nevertheless that's what UIViewController appears to do.

这篇关于UIView nextResponder如何知道UIViewController是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆