Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights
Reserved.
NSTextField
Inherits From: NSControl : NSView : NSResponder : NSObject
Conforms To: NSCoding (NSResponder)
NSObject (NSObject)
Declared In: AppKit/NSTextField.h
Class Description
An NSTextField is an NSControl object that can display a piece of text that a
user can select or edit, and which sends an action message to its target if the
user hits the Return key while editing. An NSTextField can also be linked to
other NSTextFields, so that when the user presses Tab or Shift-Tab, the object
assigned as the next or
previous field gets a message to select its
text.
An NSTextField is a good alternative to an NSText object for small regions of
editable text, since the display of the NSTextField is achieved by using a
global NSText object shared by objects all over your application, which saves
on memory usage. Each NSWindow also has an NSText object used for editing of
NSTextFields (and NSTextFieldCells in NSMatrices). An NSWindow's global NSText
object is called a field editor, since it's attached as needed to an
NSTextField to perform its editing. NSTextField allows you to specify an object
to act as an indirect delegate to the field editor; the NSTextField itself acts
as the NSText delegate if it needs to, then passes the delegate method on to
its own NSText delegate.
Setting User Access to Text
- - (BOOL)isEditable Returns whether the NSTextField's text is editable.
- - (BOOL)isSelectable Returns whether the NSTextField's text is
selectable.
- - (void)setEditable:(BOOL)flag Sets whether the NSTextField's
text is editable.
- - (void)setSelectable:(BOOL)flag Sets whether the NSTextField's
text is selectable.
Editing Text
- - (void)selectText:(id)sender Selects all of the text if it's
selectable or editable.
Setting Tab Key Behavior
- - (id)nextText Gets the object selected when the user presses Tab.
- - (id)previousText Gets the object selected when the user presses
Shift-Tab.
- - (void)setNextText:(id)anObject Sets the object selected when
the user presses Tab.
- - (void)setPreviousText:(id)anObject Sets the object selected
when the user presses Shift-Tab.
Assigning a Delegate
- - (void)setDelegate:(id)anObject Sets the delegate for messages
from the field editor to anObject.
- - (id)delegate Returns the delegate for messages from the field
editor.
Modifying Graphic Attributes
- - (NSColor *)backgroundColor Returns the color of the background.
- - (BOOL)drawsBackground Returns whether the NSTextField draws its own
background.
- - (BOOL)isBezeled Returns whether the NSTextField has a bezeled border.
- - (BOOL)isBordered Returns whether the NSTextField has a plain border.
- - (void)setBackgroundColor:(NSColor *)aColor Sets the color of
the background to aColor.
- - (void)setBezeled:(BOOL)flag Sets whether the NSTextField has a
bezeled border.
- - (void)setBordered:(BOOL)flag Sets whether the NSTextField has a
plain border.
- - (void)setDrawsBackground:(BOOL)flag Sets whether the
NSTextField draws its own background color.
- - (void)setTextColor:(NSColor *)aColor Sets the color of the
NSTextField's text to aColor.
- - (NSColor *)textColor Returns the color of the NSTextField's text.
Target and Action
- - (SEL)errorAction Returns the action method sent for an invalid value.
- - (void)setErrorAction:(SEL)aSelector Sets the action method sent
(aSelector) for an invalid value entered.
Handling Events
- - (BOOL)acceptsFirstResponder Return YES if text is editable or
selectable.
- - (void)textDidBeginEditing:(NSNotification *)notification
Invoked when there's a change in the text after the receiver gains
first responder status. The default behavior is to pass this message on to the
text delegate by posting the notification
NSControlTextDidEndEditingNotification with the receiving object and, in the
notification's dictionary, the text object (with the key NSFieldEditor) to the
default notification center.
- - (void)textDidChange:(NSNotification *)notification
Invoked upon a key-down event or paste operation that changes the receiver's
contents. The default behavior is to pass this message on to the text delegate
by posting the NSControlTextDidChangeNotification notification with the
receiving object and, in the notification's dictionary, the text object (with
the key NSFieldEditor) to the default notification center.
- - (void)textDidEndEditing:(NSNotification *)notification
Invoked when text editing ends. The default behavior is to pass this
message on to the text delegate by posting the notification
NSControlTextDidEndEditingNotification with the receiving object and, in the
notification's dictionary, the text object (with the key NSFieldEditor) to the
default notification center.
- - (BOOL)textShouldBeginEditing:(NSText *)textObject
Invoked to let the NSTextField respond to impending changes to its text and
then forwarded to the text delegate.
- - (BOOL)textShouldEndEditing:(NSText *)textObject
Invoked to let the NSTextField respond to impending loss of first responder
status and then forwarded to the text delegate.