< Previous PageNext Page > Hide TOC

Changing Text Storage

The behavior of an NSTextStorage object is best illustrated by following the messages you send to change its text.There are three stages to editing a text storage object programmatically:

  1. The first stage is to send it a beginEditing message to announce a group of changes.

  2. In the second stage, you send it some editing messages, such as deleteCharactersInRange: and addAttributes:range:, to effect the changes in characters or attributes. Each time you send such a message, the text storage object invokes edited:range:changeInLength: to track the range of its characters affected since it received the beginEditing message.

  3. For the third stage, when you’re done changing the text storage object, you send it the endEditing message. This causes it to invoke its own processEditing method, fixing attributes within the recorded range of changed characters. (See Text Attributes for information about attribute fixing.)

After fixing its attributes, the text storage object sends a message to each associated layout manager indicating the range in the text storage object that has changed, along with the nature of those changes. The layout managers in turn use this information to recalculate their glyph locations and redisplay if necessary. NSTextStorage also keeps a delegate and sends it messages before and after processing edits.



< Previous PageNext Page > Hide TOC


© 1997, 2005 Apple Computer, Inc. All Rights Reserved. (Last updated: 2005-08-11)


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.