Cocoa Event Handling



Some extracts from Apple Developer’s Manuals which are important for me. That helps me to understand how I could respond to definite event in my application.
A responder is an object that can receive events, either directly or through the responder chain, by virtue of its inheritance from the NSResponder class. NSApplication, NSWindow, NSDrawer, NSWindowController, NSView and the many descendants of these classes in the Application Kit inherit from NSResponder.
If we take a look at the following list we’ll see that not only NSResponder descendants could actually respond to that messages.

  1. The main window’s first responder and the successive responder objects up the view hierarchy
  2. The main window itself
  3. The main window’s delegate (which need not inherit from NSResponder)
  4. The application object, NSApp
  5. The application object’s delegate (which need not inherit from NSResponder)

Connecting custom controller instance of a class, derived from NSObject (or other class not rooted to NSResponder) class to NSWindow‘s or NSApplication‘s (NSApp) delegate outlet also puts controller object into FirstResponder chain.
Keep in mind sequence of responders in the chain when deciding which class should contain responding method.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s