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:
The first stage is to send it a
beginEditing
message to announce a group of changes.In the second stage, you send it some editing messages, such as
deleteCharactersInRange:
andaddAttributes:range:
, to effect the changes in characters or attributes. Each time you send such a message, the text storage object invokesedited:range:changeInLength:
to track the range of its characters affected since it received thebeginEditing
message.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 ownprocessEditing
method, fixing attributes within the recorded range of changed characters. (See Text Attribute Programming Topics 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.
Copyright © 1997, 2012 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2012-09-19