A Cocoa view controller subclass that implements responder chain patching when used in conjunction with XSWindowController
.
Also includes:
NSResponder+XSViewController
: Responder chain category
This is a reboot of the original implementation (zip). The original functionality has been retained but the API has been updated.
OS X 64 bit ARC.
Read the legacy articles below for guidance then read the header file notes.
Usage is a three step process:
- Instantiate an
XSWindowController
(or a subclass thereof). - Add
XSViewController
children to theXSWindowController
instance. - Add further
XSViewController
children toXSViewController
instances.
As the XSViewController
children are manipulated they will be added and removed from the responder chain as long as at least the topmost XSViewController
instance in any given tree has an assigned window controller.
Note that this reboot modifies the default behaviour of the original implementation. The previous implementation's behaviour, as described in the legacy documents, can be recovered like so:
// Class configuration - disallow calling NSViewController's designated initialiser
[XSViewController setRaiseExceptionForDesignatedInitialiser:YES]
XSWindowController *winController = [[MyXSWindowControllerSubclass alloc] init];
// Patch the responder chain from the window controller as opposed to the window
winController.responderChainPatchRoot = winController;
// Add controllers in descending order - that is starting with the root rather than the children
winController.addControllersToResponderChainInAscendingOrder = NO;
The various NSResponder
category methods such as - xsv_actionResponderChainFromSelf
return arrays of objects sorted in the order in which they occur in the responder chain. Both action and event responder chains can be requested.
The constructed responder chains should confirm to the chains discussed in the Apple Responder Chain info.
The original articles that accompanied the code are no longer available. However, archived versions of the articles are still accessible. These explain in some detail the reasoning that lies behind the code:
Created by Jonathan Dann and Cathy Shive on 14/04/2008.
Updated by Jonathan Mitchell on 20/11/2013.