How does UIView nextResponder know what the UIViewController is?

后端 未结 4 670
旧时难觅i
旧时难觅i 2021-02-07 20:05

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 docum

4条回答
  •  你的背包
    2021-02-07 20:29

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

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

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

    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.

    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.

提交回复
热议问题