< Previous PageNext Page > Hide TOC

Delegate Messages and Notifications

An NSTextView object can have a delegate that it informs of certain actions or pending changes to the state of the text. The delegate can be any object you choose, and one delegate can control multiple NSTextView objects (or multiple series of connected NSTextView objects). Figure 1 illustrates the activity of the delegate of an NSTextView object receiving the delegate message textView:shouldChangeTextInRange:replacementString:.


Figure 1  Delegate of an NSTextView object

Delegate of an NSTextView object

The NSText and NSTextView class reference documentation describes the delegate messages the delegate can receive. The delegating object sends a message only if the delegate implements the method.

All NSTextView objects attached to the same NSLayoutManager share the same delegate: Setting the delegate of one such text view sets the delegate for all the others. Delegate messages pass the id of the sender as an argument.

Note:  For multiple NSTextView objects attached to the same NSLayoutManager object, the argument id is that of the notifying text view, which is the first NSTextView object for the shared NSLayoutManager object. This NSTextView object is responsible for posting notifications at the appropriate times.

The notifications posted by NSTextView are:

It is particularly important for observers to register for the last of these notifications. If a new NSTextView object is added at the beginning of a series of connected NSTextView objects, it becomes the new notifying text view. It doesn’t have access to which objects are observing its group of text objects, so it posts an NSTextViewWillChangeNotifyingTextViewNotification, which allows all those observers to unregister themselves from the old notifying text view and reregister themselves with the new one. For more information, see the description for this notification in the NSTextView reference documentation.



< Previous PageNext Page > Hide TOC


© 2003, 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-02-08)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.