Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.4 and later. |
Companion guide | |
Declared in | NSTokenField.h |
NSTokenField
is a subclass of NSTextField
that provides tokenized editing similar to the address field in the Mail application.
NSTokenField
uses an NSTokenFieldCell
to implement much of the control’s functionality. NSTokenField
provides cover methods for most methods of NSTokenFieldCell
, which invoke the corresponding cell method.
Notes: In Mac OS X v10.4 and earlier, represented objects associated with token fields had to conform to NSCoding
. Starting with Mac OS X v10.5, they no longer need to.
NSTokenField
trims whitespace around tokens but it does not trim whitespace in Mac OS X versions 10.5.0 and 10.5.1. In Mac OS X v10.5.2, you get whitespace-trimming behavior by either linking against the v10.4 binary or linking against the v10.5 binary and not implementing the tokenField:representedObjectForEditingString:
method. If you do not want the whitespace-trimming behavior, link against the v10.5 binary and implement this method, returning the editing string if you have no represented object. – tokenField:displayStringForRepresentedObject:
delegate method
– tokenField:styleForRepresentedObject:
delegate method
– tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:
delegate method
– tokenField:editingStringForRepresentedObject:
delegate method
– tokenField:representedObjectForEditingString:
delegate method
– tokenField:shouldAddObjects:atIndex:
delegate method
– tokenField:readFromPasteboard:
delegate method
– tokenField:writeRepresentedObjects:toPasteboard:
delegate method
– tokenField:hasMenuForRepresentedObject:
delegate method
– tokenField:menuForRepresentedObject:
delegate method
Returns the default completion delay.
+ (NSTimeInterval)defaultCompletionDelay
The default completion delay is 0.
NSTokenField.h
Returns the default tokenizing character set.
+ (NSCharacterSet *)defaultTokenizingCharacterSet
The default tokenizing character set is “,”.
NSTokenField.h
Returns the receiver’s completion delay.
- (NSTimeInterval)completionDelay
NSTokenField.h
Sets the receiver’s completion delay.
- (void)setCompletionDelay:(NSTimeInterval)delay
NSTokenField.h
Sets the recevier’s tokenizing character set to characterSet.
- (void)setTokenizingCharacterSet:(NSCharacterSet *)characterSet
NSTokenField.h
Returns the token style of the receiver.
- (void)setTokenStyle:(NSTokenStyle)style
NSTokenField.h
Returns the receiver’s tokenizing character set.
- (NSCharacterSet *)tokenizingCharacterSet
NSTokenField.h
Returns the receiver’s token style.
- (NSTokenStyle)tokenStyle
NSTokenField.h
Allows the delegate to provide an array of appropriate completions for the contents of the receiver.
- (NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex
The token field where editing is occurring.
The partial string that is to be completed.
The index of the token being edited.
Optionally, you can return by-reference an index into the returned array that specifies which of the completions should be initially selected. If none are to be selected, return by reference -1.
An array of possible completions.
The default behavior of this method provides no completions.
NSTokenField.h
Allows the delegate to provide a string to be displayed as a proxy for the given represented object.
- (NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject
The token field.
A represented object of the token field.
The string to be used as a proxy for representedObject
. If you return nil
or do not implement this method, then representedObject is displayed as the string.
NSTokenField.h
Allows the delegate to provide a string to be edited as a proxy for a represented object.
- (NSString *)tokenField:(NSTokenField *)tokenField editingStringForRepresentedObject:(id)representedObject
If you return nil
from this method, the token field is not editable.
NSTokenField.h
Allows the delegate to specify whether the given represented object provides a menu.
- (BOOL)tokenField:(NSTokenField *)tokenField hasMenuForRepresentedObject:(id)representedObject
The token field.
A represented object of the token field.
YES
if the represented object has a menu, NO
otherwise.
By default tokens have no menus.
NSTokenField.h
Allows the delegate to provide a menu for the specified represented object.
- (NSMenu *)tokenField:(NSTokenField *)tokenField menuForRepresentedObject:(id)representedObject
The token field.
A represented object of the token field.
The menu associated with the represented object.
The returned menu should be autoreleased. By default tokens do not return menus.
NSTokenField.h
Allows the delegate to return an array of objects representing the data read from the specified pasteboard.
- (NSArray *)tokenField:(NSTokenField *)tokenField readFromPasteboard:(NSPasteboard *)pboard
NSTokenField.h
Allows the delegate to provide a represented object for the given editing string.
- (id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString:(NSString *)editingString
If your application uses some object other than an NSString
for their represented objects, you should return a new, autoreleased instance of that object from this method.
Note: In Mac OS X v10.4, NSTokenField
trims whitespace around tokens but it does not trim whitespace in Mac OS X versions 10.5.0 and 10.5.1. In Mac OS X v10.5.2, you get whitespace-trimming behavior by either linking against the v10.4 binary or linking against the v10.5 binary and not implementing the this method. If you do not want the whitespace-trimming behavior, link against the v10.5 binary and implement this method, returning the editing string if you have no represented object.
NSTokenField.h
Allows the delegate to validate the tokens to be added to the receiver at a particular location.
- (NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)tokens atIndex:(NSUInteger)index
The token field being validated.
An array of tokens to be inserted in the receiver at index
.
The index of the receiver in which the array of tokens to be validated (tokens
) will be inserted.
The array of tokens to be inserted.
The delegate can return the array unchanged or return a modified array of tokens. To reject the add completely, return an empty array. Returning nil
causes an error.
NSTokenField.h
Allows the delegate to return the token style for editing the specified represented object.
- (NSTokenStyle)tokenField:(NSTokenField *)tokenField styleForRepresentedObject:(id)representedObject
The delegate should return NSDefaultTokenStyle
, NSPlainTextTokenStyle
or NSRoundedTokenStyle
.
NSTokenField.h
Sent so the delegate can write represented objects to the pasteboard corresponding to a given array of display strings.
- (BOOL)tokenField:(NSTokenField *)tokenField writeRepresentedObjects:(NSArray *)objects toPasteboard:(NSPasteboard *)pboard
The token field.
An array of represented objects associated with the token field.
The pasteboard to which to write the represented objects.
YES
if the delegate writes the represented objects to the pasteboard, NO
otherwise. If NO
, the token field writes the display strings to the NSStringPboardType
pasteboard.
NSTokenField.h
© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-10-15)