PATH  Documentation > Mac OS X > Application Kit Reference: Objective-C

Table of Contents

NSText


Inherits from:
NSView : NSResponder : NSObject
Conforms to:
NSChangeSpelling
NSIgnoreMisspelledWords
NSCoding (NSResponder)
NSObject (NSObject)
Declared in:
AppKit/NSText.h



Class at a Glance


NSText declares the most general programmatic interface for objects that manage text. You usually use instances of its subclass, NSTextView.

Principal Attributes


Commonly Used Methods



- readRTFDFromFile: Reads an .rtf or .rtfd file.
- writeRTFDToFile:atomically: Writes the receiver's text to a file.
- string Returns the receiver's text, without attributes.
- RTFFromRange: Returns the receiver's text with attributes.
- RTFDFromRange: Returns the receiver's text with attributes and attachments.


Class Description


The NSText class declares the most general programmatic interface to objects that manage text. Cocoa offers a subclass of NSText, NSTextView, that extends the interface declared by NSText and provides much more sophisticated functionality than that declared in NSText.

NSText's initialization method creates an instance of a concrete subclass, such as NSTextView. Instances of any of these classes are generically called text objects.

Text objects are used by the Application Kit wherever text appears in interface objects: A text object draws the title of a window, the commands in a menu, the title of a button, and the items in a browser. Your application can also create text objects for its own purposes.

The text classes are unlike most other classes in the Application Kit in the richness and complexity of their interface. One of their design goals is to provide a comprehensive set of text-handling features so that you'll rarely need to create a subclass. Among other things, a text object can:

Graphical user-interface building tools (such as Interface Builder) may give you access to text objects in several different configurations, such as those found in the NSTextField, NSForm, and NSScrollView objects. These classes configure a text object for their own specific purposes. Additionally, all NSTextFields, NSForms, NSButtons within the same window-in short, all objects that access a text object through associated cells-share the same text object, reducing the memory demands of an application. Thus, it's generally best to use one of these classes whenever it meets your needs, rather than create text objects yourself. If one of these classes doesn't provide enough flexibility for your purposes, you can create text objects programmatically.

Text objects typically work closely with various other objects. Some of these-such as the delegate or an embedded graphic object-require a degree of programming on your part. Others-such as the Font Panel, spell checker, or ruler-take no effort other than deciding whether the service should be enabled or disabled. Several of the following sections discuss these interrelationships.


Plain and Rich Text Objects


Text objects are differentiated into two groups: those that allow only one set of text attributes for all of their text, and those that allow multiple fonts, sizes, indents, and other attributes for different sets of characters and paragraphs. Text objects in the former group are called plain text objects, while those in the latter are called rich text objects. You can control whether a text object is plain or rich using the setRichText: method. Rich text objects are also capable of allowing the user to drag images and files into them. This behavior is controlled by the setImportsGraphics: method.

A rich NSText object can use RTF (Rich Text Format) as an interchange format. Not all RTF control words are supported: On input, an NSText object ignores any control word it doesn't recognize; some of those it can read and interpret it doesn't write out. The table below lists the RTF control words that any text object recognizes. Subclasses may recognize more.


Control Word Read Write
\ansi yes yes
\b yes yes
\cb yes yes
\cf yes yes
\colortbl yes yes
\dnn yes yes
\fin yes yes
\fn yes yes
\fonttbl yes yes
\fsn yes yes
\i yes yes
\lin yes yes
\margrn yes yes
\paperwn yes yes
\mac yes no
\margln yes yes
\par yes yes
\pard yes no
\pca yes no
\qc yes yes
\ql yes yes
\qr yes yes
\sn yes no
\tab yes yes
\upn yes yes


Notifying a Text Object's Delegate


Many of an NSText object's actions can be controlled through an associated object, the NSText object's delegate. The delegate can be any object you choose, and one delegate can control multiple NSText objects. If it implements any of the following methods, the delegate receives the corresponding message at the appropriate time:

Of special note are the two "textShould..." methods. These methods are requests for permission. Any time a text object begins an operation that would change its text or attributes, it uses textShouldBeginEditing: to request approval for the change. The delegate can return YES to permit the change, or NO to forbid it. Similarly, textShouldEndEditing: enables the delegate to prevent a text object from ending editing, such as when it contains an invalid value.


Adding Graphics and Other Attachments to the Text


A rich text object may allow graphics or other file attachments to be embedded in the text. Each graphic is treated as a single (possibly large) "character": The text's line height and character placement are adjusted to accommodate the graphic. Graphics are embedded in the text in either of two ways: programmatically or directly through user actions. In the programmatic approach, graphic objects can be added using replaceRange:WithRTFD:, or through a more specific method defined by a subclass.

An alternate means of adding an image or other attachment to the text is for the user to drag an image or other file directly into the text object. The text object automatically creates an attachment object to manage the display of the image. This feature requires a rich text object that has been configured to receive dragged images using the setImportsGraphics: method.

Images that have been imported can be written as part of an RTFD document. RTFD documents use a file package, or directory, to store the components of the document (the "D" stands for "directory"). The file package has the name of the document plus an .rtfd extension. The file package always contains a file called TXT.rtf for the text of the document, and one or more TIFF or EPS files for the images, plus the files for other attachments. A text object can transfer information in an RTFD document to a file and read it from a file using the writeRTFDToFile:atomically: and readRTFDFromFile: methods.


Working with the Font Panel


Text objects are designed to work with the Application Kit's font conversion system, defined by the NSFontPanel and NSFontManager classes. By default, a text object keeps the Font Panel updated with the first font in its selection, or of its typing attributes (defined below). It also changes the font in response to messages from the Font Panel and Font menu. Such changes apply to the selected text or typing attributes for a rich text object, or to all the text in a plain text object. You can turn this behavior off using the setUsesFontPanel: method. Doing so is recommended for a text object that serves as a field editor, for example.


Working with Rulers and Paragraph Styles


Text objects also provide for a ruler, by which the user can edit paragraph attributes such as indents and tabs. NSTextView works with the NSRulerView class and uses the NSTextStorage and NSParagraphStyle classes to handle paragraph attributes. To show or hide a text object's ruler, use the toggleRuler: action method. Similar to the Font Panel, NSTextView can be set not to use a ruler with the setUsesRuler: method.




Constants


These constants specify text alignment:


Constants Description
NSLeftTextAlignment Description forthcoming.
NSRightTextAlignment Description forthcoming.
NSCenterTextAlignment Description forthcoming.
NSJustifiedTextAlignment Description forthcoming.
NSNaturalTextAlignment Use the natural alignment of the text's script

These constants specify the movement between fields. They are used by NSTextDidEndEditingNotification.


Constants Description
NSIllegalTextMovement Description forthcoming.
NSReturnTextMovement Description forthcoming.
NSTabTextMovement Description forthcoming.
NSBacktabTextMovement Description forthcoming.
NSLeftTextMovement Description forthcoming.
NSRightTextMovement Description forthcoming.
NSUpTextMovement Description forthcoming.
NSDownTextMovement Description forthcoming.

These constants specify several commonly-used Unicode characters.


Constants Description
NSParagraphSeparatorCharacter Description forthcoming.
NSLineSeparatorCharacter Description forthcoming.
NSTabCharacter Description forthcoming.
NSFormFeedCharacter Description forthcoming.
NSNewlineCharacter Description forthcoming.
NSCarriageReturnCharacter Description forthcoming.
NSEnterCharacter Description forthcoming.
NSBackspaceCharacter Description forthcoming.
NSDeleteCharacter Description forthcoming.



Adopted Protocols


NSChangeSpelling
- changeSpelling:
NSIgnoreMisspelledWords
- ignoreSpelling:


Method Types


Getting the characters
- string
Setting graphic attributes
- setBackgroundColor:
- backgroundColor
- setDrawsBackground:
- drawsBackground
Setting behavioral attributes
- setEditable:
- isEditable
- setSelectable:
- isSelectable
- setFieldEditor:
- isFieldEditor
- setRichText:
- isRichText
- setImportsGraphics:
- importsGraphics
Using the Font Panel and menu
- setUsesFontPanel:
- usesFontPanel
Using the ruler
- toggleRuler:
- isRulerVisible
Changing the selection
- setSelectedRange:
- selectedRange
Replacing text
- replaceCharactersInRange:withRTF:
- replaceCharactersInRange:withRTFD:
- replaceCharactersInRange:withString:
- setString:
Action methods for editing
- selectAll:
- copy:
- cut:
- paste:
- copyFont:
- pasteFont:
- copyRuler:
- pasteRuler:
- delete:
Changing the font
- changeFont:
- setFont:
- setFont:range:
- font
Setting text alignment
- setAlignment:
- alignCenter:
- alignLeft:
- alignRight:
- alignment
Setting text color
- setTextColor:
- setTextColor:range:
- textColor
Setting super- and subscripting
- superscript:
- subscript:
- unscript:
Underlining text
- underline:
Reading and writing RTF
- readRTFDFromFile:
- writeRTFDToFile:atomically:
- RTFDFromRange:
- RTFFromRange:
Checking spelling
- checkSpelling:
- showGuessPanel:
Constraining size
- setMaxSize:
- maxSize
- setMinSize:
- minSize
- setVerticallyResizable:
- isVerticallyResizable
- setHorizontallyResizable:
- isHorizontallyResizable
- sizeToFit
Scrolling
- scrollRangeToVisible:
Setting the delegate
- setDelegate:
- delegate


Instance Methods



alignCenter:

- (void)alignCenter:(id)sender

This action method applies center alignment to selected paragraphs (or all text if the receiver is a plain text object).

See Also: - alignLeft:, - alignRight:, - alignment, - setAlignment:



alignLeft:

- (void)alignLeft:(id)sender

This action method applies left alignment to selected paragraphs (or all text if the receiver is a plain text object).

See Also: - alignCenter:, - alignRight:, - alignment, - setAlignment:



alignRight:

- (void)alignRight:(id)sender

This action method applies right alignment to selected paragraphs (or all text if the receiver is a plain text object).

See Also: - alignLeft:, - alignCenter:, - alignment, - setAlignment:



alignment

- (NSTextAlignment)alignment

Returns the alignment of the first selected paragraph, or of all text for a plain text object. This value is one of the alignments described in "Constants" .

Text using NSNaturalTextAlignment is actually displayed using one of the other alignments, depending on the natural alignment of the text's script.



backgroundColor

- (NSColor *)backgroundColor

Returns the receiver's background color.

See Also: - drawsBackground, - setBackgroundColor:



changeFont:

- (void)changeFont:(id)sender

This action method changes the font of the selection for a rich text object, or of all text for a plain text object. If the receiver doesn't use the Font Panel, this method does nothing.

This method changes the font by sending a convertFont: message to the shared NSFontManager, and applying each NSFont returned to the appropriate text. See the NSFontManager class specification for more information on font conversion.

See Also: - usesFontPanel



checkSpelling:

- (void)checkSpelling:(id)sender

This action method searches for a misspelled word in the receiver's text. The search starts at the end of the selection and continues until it reaches a word suspected of being misspelled or the end of the text. If a word isn't recognized by the spelling server, a showGuessPanel: message then opens the Guess panel and allows the user to make a correction or add the word to the local dictionary.

See Also: - showGuessPanel:



copy:

- (void)copy:(id)sender

This action method copies the selected text onto the general pasteboard, in as many formats as the receiver supports. A plain text object uses NSStringPboardType for plain text, and a rich text object also uses NSRTFPboardType.

See Also: - copyFont:, - copyRuler:, - cut:, - paste:



copyFont:

- (void)copyFont:(id)sender

This action method copies the font information for the first character of the selection (or for the insertion point) onto the font pasteboard, as NSFontPboardType.

See Also: - copy:, - copyRuler:, - cut:, - paste:



copyRuler:

- (void)copyRuler:(id)sender

This action method copies the paragraph style information for first selected paragraph onto the ruler pasteboard, as NSRulerPboardType, and expands the selection to paragraph boundaries.

See Also: - copy:, - copyFont:, - cut:, - paste:



cut:

- (void)cut:(id)sender

This action method deletes the selected text and places it onto the general pasteboard, in as many formats as the receiver supports. A plain text object uses NSStringPboardType for plain text, and a rich text object also uses NSRTFPboardType.

See Also: - delete:, - copy:, - copyFont:, - copyRuler:, - paste:



delegate

- (id)delegate

Returns the receiver's delegate, or nil if it has none.

See Also: - setDelegate:



delete:

- (void)delete:(id)sender

This action method deletes the selected text.

See Also: - cut:



drawsBackground

- (BOOL)drawsBackground

Returns YES if the receiver draws its background, NO if it doesn't.

See Also: - backgroundColor, - setDrawsBackground:



font

- (NSFont *)font

Returns the font of the first character in the receiver's text, or of the insertion point if there's no text.

See Also: - setFont:, - setFont:range:



importsGraphics

- (BOOL)importsGraphics

Returns YES if the receiver allows the user to import files by dragging, NO if it doesn't. A text object that accepts dragged files is also a rich text object.

See Also: - isRichText, - setImportsGraphics:



isEditable

- (BOOL)isEditable

Returns YES if the receiver allows the user to edit text, NO if it doesn't. You can change the receiver's text programmatically regardless of this setting.

If the receiver is editable, it's also selectable.

See Also: - isSelectable, - setEditable:



isFieldEditor

- (BOOL)isFieldEditor

Returns YES if the receiver interprets Tab, Shift-Tab, and Return (Enter) as cues to end editing, and possibly to change the first responder; NO if it accepts them as text input. See the NSWindow class specification for more information on field editors. By default, NSText objects don't behave as field editors.

See Also: - setFieldEditor:



isHorizontallyResizable

- (BOOL)isHorizontallyResizable

Returns YES if the receiver automatically changes its width to accommodate the width of its text, NO if it doesn't.

See Also: - isVerticallyResizable, - setHorizontallyResizable:



isRichText

- (BOOL)isRichText

Returns YES if the receiver allows the user to apply attributes to specific ranges of the text, NO if it doesn't.

See Also: - importsGraphics, - setRichText:



isRulerVisible

- (BOOL)isRulerVisible

Returns YES if the receiver's enclosing scroll view shows its ruler, NO otherwise.

See Also: - toggleRuler:



isSelectable

- (BOOL)isSelectable

Returns YES if the receiver allows the user to select text, NO if it doesn't.

See Also: - isEditable, - setSelectable:



isVerticallyResizable

- (BOOL)isVerticallyResizable

Returns YES if the receiver automatically changes its height to accommodate the height of its text, NO if it doesn't.

See Also: - isHorizontallyResizable, - setVerticallyResizable:



maxSize

- (NSSize)maxSize

Returns the receiver's maximum size.

See Also: - minSize, - setMaxSize:



minSize

- (NSSize)minSize

Returns the receiver's minimum size.

See Also: - maxSize, - setMinSize:



paste:

- (void)paste:(id)sender

This action method pastes text from the general pasteboard at the insertion point or over the selection.

See Also: - copy:, - cut:, - pasteFont:, - pasteRuler:



pasteFont:

- (void)pasteFont:(id)sender

This action method pastes font information from the font pasteboard onto the selected text or insertion point of a rich text object, or over all text of a plain text object.

See Also: - copyFont:, - pasteRuler:



pasteRuler:

- (void)pasteRuler:(id)sender

This action method pastes paragraph style information from the ruler pasteboard onto the selected paragraphs of a rich text object. It doesn't apply to a plain text object.

See Also: - copyFont:, - pasteRuler:



readRTFDFromFile:

- (BOOL)readRTFDFromFile:(NSString *)path

Attempts to read the RTFD file at path, returning YES if successful and NO if not. path should be the path for an .rtf file or an .rtfd file wrapper, not for the RTF file within an .rtfd file wrapper

See Also: - writeRTFDToFile:atomically:



replaceCharactersInRange:withString:

- (void)replaceCharactersInRange:(NSRange)aRange withString:(NSString *)aString

Replaces the characters in aRange with aString. For a rich text object, the text of aString is assigned the formatting attributes of the first character of the text it replaces, or of the character immediately before aRange if the range's length is zero. If the range's location is zero, the formatting attributes of the first character in the receiver are used.

See Also: - replaceCharactersInRange:withRTF:, - replaceCharactersInRange:withRTFD:



replaceCharactersInRange:withRTF:

- (void)replaceCharactersInRange:(NSRange)aRange withRTF:(NSData *)rtfData

Replaces the characters in aRange with RTF text interpreted from rtfData. This method applies only to rich text objects.

See Also: - replaceCharactersInRange:withRTFD:, - replaceCharactersInRange:withString:



replaceCharactersInRange:withRTFD:

- (void)replaceCharactersInRange:(NSRange)aRange withRTFD:(NSData *)rtfdData

Replaces the characters in aRange with RTFD text interpreted from rtfdData. This method applies only to rich text objects.

See Also: - replaceCharactersInRange:withRTF:, - replaceCharactersInRange:withString:



RTFDFromRange:

- (NSData *)RTFDFromRange:(NSRange)aRange

Returns an NSData object that contains an RTFD stream corresponding to the characters and attributes within aRange. Raises an NSRangeException if any part of aRange lies beyond the end of the receiver's characters.

When writing data to the pasteboard, you can use the NSData object as the first argument to NSPasteboard's setData:forType: method, with a second argument of NSRTFDPboardType.

See Also: - RTFFromRange:



RTFFromRange:

public NSData RTFFromRange(NSRange aRange)

Returns an NSData object that contains an RTF stream corresponding to the characters and attributes within aRange, omitting any attachment characters and attributes. Raises an NSRangeException if any part of aRange lies beyond the end of the receiver's characters.

When writing data to the pasteboard, you can use the NSData object as the first argument to NSPasteboard's setData:forType: method, with a second argument of NSRTFPboardType.

See Also: - RTFDFromRange:



scrollRangeToVisible:

- (void)scrollRangeToVisible:(NSRange)aRange

Scrolls the receiver in its enclosing scroll view so the first characters of aRange are visible.

selectAll:

- (void)selectAll:(id)sender

This action method selects all of the receiver's text.

selectedRange

- (NSRange)selectedRange

Returns the range of selected characters.

See Also: - setSelectedRange:



setAlignment:

- (void)setAlignment:(NSTextAlignment)mode

Sets the alignment of all the receiver's text to mode. mode may be one of the alignments described in "Constants" .

Text using NSNaturalTextAlignment is actually displayed using one of the other alignments, depending on the natural alignment of the text's script.

See Also: - alignment, - alignLeft:, - alignCenter:, - alignRight:



setBackgroundColor:

- (void)setBackgroundColor:(NSColor *)aColor

Sets the receiver's background color to aColor.

See Also: - setDrawsBackground:, - backgroundColor



setDelegate:

- (void)setDelegate:(id)anObject

Sets the receiver's delegate to anObject, without retaining it.

See Also: - delegate



setDrawsBackground:

- (void)setDrawsBackground:(BOOL)flag

Controls whether the receiver draws its background. If flag is YES, the receiver fills its background with the background color; if flag is NO, it doesn't.

See Also: - setBackgroundColor:, - drawsBackground



setEditable:

- (void)setEditable:(BOOL)flag

Controls whether the receiver allows the user to edit its text. If flag is YES, the receiver allows the user to edit text and attributes; if flag is NO, it doesn't. You can change the receiver's text programmatically regardless of this setting. If the receiver is made editable, it's also made selectable. NSText objects are by default editable.

See Also: - setSelectable:, - isEditable



setFieldEditor:

- (void)setFieldEditor:(BOOL)flag

Controls whether the receiver interprets Tab, Shift-Tab, and Return (Enter) as cues to end editing, and possibly to change the first responder. If flag is YES, it does; if flag is NO, it doesn't, instead accepting these characters as text input. See the NSWindow class specification for more information on field editors. By default, NSText objects don't behave as field editors.

See Also: - isFieldEditor



setFont:

- (void)setFont:(NSFont *)aFont

Sets the font of all the receiver's text to aFont.

See Also: - setFont:range:, - font



setFont:range:

- (void)setFont:(NSFont *)aFont range:(NSRange)aRange

Sets the font of characters within aRange to aFont. This method applies only to a rich text object.

See Also: - setFont:, - font



setHorizontallyResizable:

- (void)setHorizontallyResizable:(BOOL)flag

Controls whether the receiver changes its width to fit the width of its text. If flag is YES it does; if flag is NO it doesn't.

See Also: - setVerticallyResizable:, - isHorizontallyResizable



setImportsGraphics:

- (void)setImportsGraphics:(BOOL)flag

Controls whether the receiver allows the user to import files by dragging. If flag is YES, it does; if flag is NO, it doesn't. If the receiver is set to accept dragged files, it's also made a rich text object. Subclasses may or may not accept dragged files by default.

See Also: - setRichText:, - importsGraphics



setMaxSize:

- (void)setMaxSize:(NSSize)aSize

Sets the receiver's maximum size to aSize.

See Also: - setMinSize:, - maxSize



setMinSize:

- (void)setMinSize:(NSSize)aSize

Sets the receiver's minimum size to aSize.

See Also: - setMaxSize:, - minSize



setRichText:

- (void)setRichText:(BOOL)flag

Controls whether the receiver allows the user to apply attributes to specific ranges of the text. If flag is YES it does; if flag is NO it doesn't. If flag is NO, the receiver is also set not to accept dragged files. Subclasses may or may not let the user apply multiple attributes to the text and accept drag files by default.

See Also: - isRichText, - setImportsGraphics:



setSelectable:

- (void)setSelectable:(BOOL)flag

Controls whether the receiver allows the user to select its text. If flag is YES, the receiver allows the user to select text; if flag is NO, it doesn't. You can set selections programmatically regardless of this setting. If the receiver is made not selectable, it's also made not editable. NSText objects are by default editable and selectable.

See Also: - setEditable:, - isSelectable



setSelectedRange:

- (void)setSelectedRange:(NSRange)aRange

Selects the receiver's characters within aRange.

See Also: - selectedRange



setString:

- (void)setString:(NSString *)aString

Replaces the receiver's entire text with aString, applying the formatting attributes of the old first character to its new contents.

setTextColor:

- (void)setTextColor:(NSColor *)aColor

Sets the text color of all characters in the receiver to aColor. Removes the text color attribute if aColor is nil.

See Also: - setTextColor:range:, - textColor



setTextColor:range:

- (void)setTextColor:(NSColor *)aColor range:(NSRange)aRange

Sets the text color of characters within aRange to aColor. Removes the text color attribute if aColor is nil. This method applies only to rich text objects.

See Also: - setTextColor:, - textColor



setUsesFontPanel:

- (void)setUsesFontPanel:(BOOL)flag

Controls whether the receiver uses the Font Panel and Font menu. If flag is YES, the receiver responds to messages from the Font Panel and from the Font menu, and updates the Font Panel with the selection font whenever it changes. If flag is NO the receiver doesn't do any of this. By default, an NSText object uses the Font Panel and menu.

See Also: - usesFontPanel



setVerticallyResizable:

- (void)setVerticallyResizable:(BOOL)flag

Controls whether the receiver changes its height to fit the height of its text. If flag is YES it does; if flag is NO it doesn't.

See Also: - setHorizontallyResizable:, - isVerticallyResizable



showGuessPanel:

- (void)showGuessPanel:(id)sender

This action method opens the Spelling panel, allowing the user to make a correction during spell checking.

See Also: - checkSpelling:



sizeToFit

- (void)sizeToFit

Resizes the receiver to fit its text.

See Also: - isHorizontallyResizable, - isVerticallyResizable



string

- (NSString *)string

Returns the characters of the receiver's text. For performance reasons, this method returns the current backing store of the text object. If you want to maintain a snapshot of this as you manipulate the text storage, you should make a copy of the appropriate substring.

See Also: - setString:



subscript:

- (void)subscript:(id)sender

This action method applies a subscript attribute to selected text (or all text if the receiver is a plain text object), lowering its baseline offset by a predefined amount.

See Also: - subscript:, - unscript:, - lowerBaseline: (NSTextView)



superscript:

- (void)superscript:(id)sender

This action method applies a superscript attribute to selected text (or all text if the receiver is a plain text object), raising its baseline offset by a predefined amount.

See Also: - subscript:, - unscript:, - raiseBaseline: (NSTextView)



textColor

- (NSColor *)textColor

Returns the color of the receiver's first character, or for the insertion point if there's no text.

See Also: - setTextColor:, - setTextColor:range:



toggleRuler:

- (void)toggleRuler:(id)sender

This action method shows or hides the ruler, if the receiver is enclosed in a scroll view.

underline:

- (void)underline:(id)sender

This action method underlines selected text for a rich text object, or all text for a plain text object.

unscript:

- (void)unscript:(id)sender

This action method removes any superscripting or subscripting from selected text (or all text if the receiver is a plain text object).

See Also: - subscript:, - superscript:, - raiseBaseline: (NSTextView), - lowerBaseline: (NSTextView)



usesFontPanel

- (BOOL)usesFontPanel

Returns YES if the receiver uses the Font Panel, NO otherwise.

See Also: - setUsesFontPanel:



writeRTFDToFile:atomically:

- (BOOL)writeRTFDToFile:(NSString *)path atomically:(BOOL)atomicFlag

Writes the receiver's text as RTF with attachments to a file or directory at path. Returns YES on success and NO on failure. If atomicFlag is YES, attempts to write the file safely so that an existing file at path is not overwritten, nor does a new file at path actually get created, unless the write is successful.

See Also: - RTFFromRange:, - RTFDFromRange:, - readRTFDFromFile:




Methods Implemented By the Delegate


textDidBeginEditing:

- (void)textDidBeginEditing:(NSNotification *)aNotification

Informs the delegate that the text object has begun editing (that the user has begun changing it). The name of aNotification is NSTextViewDidBeingEditingNotification.

textDidChange:

- (void)textDidChange:(NSNotification *)aNotification

Informs the delegate that the text object has changed its characters or formatting attributes. The name of aNotification is NSTextViewDidChangeNotification.

textDidEndEditing:

- (void)textDidEndEditing:(NSNotification *)aNotification

Informs the delegate that the text object has finished editing (that it has resigned first responder status). The name of aNotification is NSTextViewDidEndEditingNotification.

textShouldBeginEditing:

- (BOOL)textShouldBeginEditing:(NSText *)aTextObject

Invoked from a text object's implementation of becomeFirstResponder, this method requests permission for aTextObject to begin editing. If the delegate returns YES, the text object proceeds to make changes. If the delegate returns NO, the text object abandons the editing operation. This method is invoked whenever aTextObject attempts to become first responder.

See Also: - makeFirstResponder: (NSWindow), - becomeFirstResponder (NSResponder)



textShouldEndEditing:

- (BOOL)textShouldEndEditing:(NSText *)aTextObject

Invoked from a text object's implementation of resignFirstResponder, this method requests permission for aTextObject to end editing. If the delegate returns YES, the text object proceeds to finish editing and resign first responder status. If the delegate returns NO, the text object selects all of its text and remains the first responder.

See Also: - resignFirstResponder (NSResponder)




Notifications


NSTextDidBeginEditingNotification

Posted when an NSText object begins any operation that changes characters or formatting attributes. The notification contains a notification object but no userInfo dictionary. The notification object is the notifying NSText object.

NSTextDidChangeNotification

Posted after an NSText object performs any operation that changes characters or formatting attributes. The notification contains a notification object but no userInfo dictionary. The notification object is the notifying NSText object.

NSTextDidEndEditingNotification

Description forthcoming.

Table of Contents