Class

NSResponder

An abstract class that forms the basis of event and command processing in AppKit.

Declaration

@interface NSResponder : NSObject

Overview

The core classes—NSApplication, NSWindow, and NSView—inherit from NSResponder, as must any class that handles events. The responder model is built around three components: event messages, action messages, and the responder chain.

NSResponder also plays an important role in the presentation of error information. The default implementations of the presentError: and presentError:modalForWindow:delegate:didPresentSelector:contextInfo: methods send willPresentError: to self, thereby giving subclasses the opportunity to customize the localized information presented in error alerts. NSResponder then forwards the message to the next responder, passing it the customized NSError object. The exact path up the modified responder chain depends on the type of application window:

  • Window owned by document: view > superviews > window > window controller > document object > document controller > the application object

  • Window with window controller but no documents: view > superviews > window > window controller > the application object

  • Window with no window controllers: view > superviews > window > the application object

NSApplication displays a document-modal error alert and, if the error object has a recovery attempter, gives it a chance to recover from the error. (A recovery attempter is an object that conforms to the NSErrorRecoveryAttempting informal protocol.)

Topics

Changing the First Responder

acceptsFirstResponder

A Boolean value that indicates whether the responder accepts first responder status.

- becomeFirstResponder

Notifies the receiver that it’s about to become first responder in its NSWindow.

- resignFirstResponder

Notifies the receiver that it’s been asked to relinquish its status as first responder in its window.

- validateProposedFirstResponder:forEvent:

Allows controls to determine when they should become first responder.

Managing the Next Responder

nextResponder

The next responder after this one, or nil if it has none.

Responding to Mouse Events

- mouseDown:

Informs the receiver that the user has pressed the left mouse button.

- mouseDragged:

Informs the receiver that the user has moved the mouse with the left button pressed.

- mouseUp:

Informs the receiver that the user has released the left mouse button.

- mouseMoved:

Informs the receiver that the mouse has moved.

- mouseEntered:

Informs the receiver that the cursor has entered a tracking rectangle.

- mouseExited:

Informs the receiver that the cursor has exited a tracking rectangle.

- rightMouseDown:

Informs the receiver that the user has pressed the right mouse button.

- rightMouseDragged:

Informs the receiver that the user has moved the mouse with the right button pressed.

- rightMouseUp:

Informs the receiver that the user has released the right mouse button.

- otherMouseDown:

Informs the receiver that the user has pressed a mouse button other than the left or right one.

- otherMouseDragged:

Informs the receiver that the user has moved the mouse with a button other than the left or right button pressed.

- otherMouseUp:

Informs the receiver that the user has released a mouse button other than the left or right button.

Responding to Key Events

- keyDown:

Informs the receiver that the user has pressed a key.

- keyUp:

Informs the receiver that the user has released a key.

- interpretKeyEvents:

Handles a series of key events.

- performKeyEquivalent:

Handle a key equivalent.

- performMnemonic:

Handle a mnemonic.

Deprecated
- flushBufferedKeyEvents

Clears any unprocessed key events when overridden by subclasses.

Responding to Pressure Changes

- pressureChangeWithEvent:

Indicates a pressure change as the result of a user input event on a system that supports pressure sensitivity.

Responding to Other Kinds of Events

- cursorUpdate:

Informs the receiver that the mouse cursor has moved into a cursor rectangle.

- flagsChanged:

Informs the receiver that the user has pressed or released a modifier key (Shift, Control, and so on).

- tabletPoint:

Informs the receiver that a tablet-point event has occurred.

- tabletProximity:

Informs the receiver that a tablet-proximity event has occurred.

- helpRequested:

Displays context-sensitive help for the receiver if help has been registered.

- scrollWheel:

Informs the receiver that the mouse’s scroll wheel has moved.

- quickLookWithEvent:

Performs a Quick Look on the content at the location specified by the supplied event.

Responding to Action Messages

- supplementalTargetForAction:sender:

Finds a target for an action method.

Action Messages

Implement action messages in your first responders to handle common tasks.

Handling Window Restoration

- encodeRestorableStateWithCoder:

Saves the interface-related state of the responder.

- restoreStateWithCoder:

Restores the interface-related state of the responder.

restorableStateKeyPaths

Returns an array of key paths representing the restorable attributes of the responder.

- invalidateRestorableState

Marks the responder’s interface-related state as dirty.

Supporting User Activities

userActivity

An object encapsulating a user activity supported by this responder.

- updateUserActivityState:

Updates the state of the given user activity.

Presenting and Customizing Error Information

- presentError:

Presents an error alert to the user as an application-modal dialog.

- presentError:modalForWindow:delegate:didPresentSelector:contextInfo:

Presents an error alert to the user as a document-modal sheet attached to document window.

- willPresentError:

Returns a custom version of the supplied error object that is more suitable for presentation in alert sheets and dialogs.

Dispatching Messages

- tryToPerform:with:

Attempts to perform the method indicated by an action with a specified argument.

Managing a Responder’s Menu

menu

Returns the responder’s menu.

Updating the Services Menu

- validRequestorForSendType:returnType:

Overridden by subclasses to determine what services are available.

Getting the Undo Manager

undoManager

The undo manager for this responder.

Testing Events

- shouldBeTreatedAsInkEvent:

Indicates whether a pen-down event should be treated as an ink event.

Terminating the Responder Chain

- noResponderFor:

Handles the case where an event or action message falls off the end of the responder chain.

Setting the Interface Style

- setInterfaceStyle:

Sets the receiver’s style to the style specified by interfaceStyle, such as NSMacintoshInterfaceStyle or NSWindows95InterfaceStyle.

Deprecated
- interfaceStyle

Returns the receiver’s interface style.

Deprecated
NSInterfaceStyleDefault

For more information, see the function NSInterfaceStyleForKey.

Deprecated

Touch and Gesture Events

- beginGestureWithEvent:

Informs the receiver that the user has begun a touch gesture.

- endGestureWithEvent:

Informs the receiver that the user has ended a touch gesture.

- magnifyWithEvent:

Informs the receiver that the user has begun a pinch gesture.

- rotateWithEvent:

Informs the receiver that the user has begun a rotation gesture.

- swipeWithEvent:

Informs the receiver that the user has begun a swipe gesture.

- touchesBeganWithEvent:

Informs the receiver that new set of touches has been recognized.

- touchesMovedWithEvent:

Informs the receiver that one or more touches has moved.

- touchesCancelledWithEvent:

Informs the receiver that tracking of touches has been cancelled for any reason.

- touchesEndedWithEvent:

Returns that a set of touches have been removed.

- wantsForwardedScrollEventsForAxis:

Returns whether to forward elastic scrolling gesture events up the responder.

- smartMagnifyWithEvent:

Informs the receiver that the user performed a smart zoom gesture.

- wantsScrollEventsForSwipeTrackingOnAxis:

Implement this method to track gesture scroll events such as a swipe.

NSEventGestureAxis

The gesture tracking axis.

Performing Text Find Actions

- performTextFinderAction:

Performs all find oriented actions.

Instance Properties

touchBar

The NSTouchBar object associated with the responder.

Instance Methods

- makeTouchBar

Your custom subclass of the NSResponder class should override this method to create and configure your subclass’s default NSTouchBar object.

Relationships

Inherits From

Conforms To