How do Responder Chain Works in IPhone? What are the “next responders”?

后端 未结 5 1467
难免孤独
难免孤独 2021-01-31 09:01

This is what the documentation says:

If the first responder [to an event or action message] cannot handle an event or action message, it forwards it to th

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 10:04

    The responder chain is a series of linked responder objects. It starts with the first responder and end with the app object. If the first responder cannot handle an event, it forwards the event to the next responder in the responder chain.

    A responder object is an object that can respond to and handle events. The UIResponder class is the base class for all responder objects, and it defines the programmatic interface not only for event handling but also for common responder behavior. Instances of the UIApplication, UIViewController, and UIView classes are responders, which means that all views and most key controller objects are responders. Note that Core Animation layers are not responders.

    The first responder is designated to receive events first. Typically, the first responder is a view object. An object becomes the first responder by doing two things:

    Overriding the canBecomeFirstResponder method to return YES.
    
    Receiving a becomeFirstResponder message. If necessary, an object can send itself this message.
    

    refer Apple doc for more explanation.

提交回复
热议问题