Response and response chain

Source: Internet
Author: User

Core Application objects-NSApplication,NSWindow, AndNSView-They are all responders. They areNSResponder(See Figure 6-19. This abstract class defines the interfaces and expected behaviors of objects that can respond to events.NSResponderOr partially implement this behavior.


Figure 6-19Nsresponder and its direct subclass


Note:There are two other Application Kit classes that are directly inherited fromNSResponder:NSWindowControllerAndNSDrawer. AlthoughNSWindowControllerIs part of the cocoa document architecture (see descriptions in "other cocoa architectures"). Both classes are not at the center of the core cocoa application architecture.

NSResponderClass defines an interface for the three main models or mechanisms of the core application architecture:

  • It declares some processingEvent message(That is, messages originating from user events, such as events such as mouse clicks or press keys.

  • It declares dozens of processesAction MessageThey are closely related to standard key bindings (such as those that move insertion points inside the text. Action messages are distributed to the target object. If the target is not specified, the application is responsible for retrieving the appropriate response.

  • It defines a set of methods for assigning and managing contacts in an application. These responders make up what we knowResponder chain-That is, a series of responders, and event or action messages are transmitted between them until the objects that can be processed are found.

The responder chain is the central mechanism of the Application Kit event processing architecture. It is composed of a series of connected responder objects. event or action messages can be transmitted along these objects. As shown in Figure 6-20, if a responder object cannot process an event or action-that is, it does not respond to that message or knows that event, then the message is resent to the next responder in the chain. The message is passed up along the responder chain to a higher level object until it is finally processed (if it is still not processed, it will be discarded ).


Figure 6-20Responder chain


When the Application Kit constructs an object in the application, it establishes a responder chain for each window. The basic object in the responder chain isNSWindowObject and its view level. A view with a lower level gives priority to event processing or action messages than a view with a higher level.NSWindowWarranty has oneFirst responderIt is usually the selected view in the current window, the window usually gives it the opportunity to respond to the message first. For event messages, the responder links toNSWindowObject as the end, although other objects can be added as the next ResponderNSWindowObject.

For action messages, the response chain is more complex. Two factors determine the response link of an action message:

  • If the application currently has both the main window and the keyboard focus window, the responder chain of both windows will participate. The responder chain of the keyboard focus window will first get the opportunity to process the action. At the end of each window chain, cocoa willNSWindowThe opportunity for the delegate object to respond to the action; at the end of the merged responder chain isNSAppAnd its delegate object.

  • Application Type-whether it is a simple document-based program or a program using a window controller-This determines the type and location of the responder object in the chain.

NSResponderClass also contains methods for error representation and recovery, message distribution, application help, and other functions.

= ======================================

The above is Apple's official documentation. The address is:

Http://www.apple.com.cn/developer/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CoreAppArchitecture/chapter_7_section_6.html

Pay attention to the following points for understanding:

1. the above document describes the logic of the responder and the responder chain in Mac OS X. This is basically the same as the logic in iOS, but the implementation class is different.

2. nsapplication, nswindow, and nsview correspond to uiapplication, uiwindow, and uiview in IOS respectively.


3. When the Application Kit constructs an object in the application, it establishes a responder chain for each window. In iOS, It also corresponds to the uikit framework, the iPhone application has only one window, so there is only one response

User chain.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.