| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.6 and later. |
| Companion guide | |
| Declared in | NSTokenFieldCell.h |
The NSTokenFieldCellDelegate protocol defines the optional methods implemented by delegates of NSTokenFieldCell objects.
– tokenFieldCell:completionsForSubstring:indexOfToken:indexOfSelectedItem:
– tokenFieldCell:editingStringForRepresentedObject:
– tokenFieldCell:representedObjectForEditingString:
– tokenFieldCell:shouldAddObjects:atIndex:
Allows the delegate to provide an array of appropriate completions for the contents of the receiver.
- (NSArray *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex
The token field cell that sent the message.
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 strings that are possible completions.
If the delegate does not implement this method, no completions are provided.
NSTokenFieldCell.hAllows the delegate to provide a string to be displayed as a proxy for the represented object.
- (NSString *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell displayStringForRepresentedObject:(id)representedObject
The token field cell that sent the message.
A represented object of the token field cell.
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.
NSTokenFieldCell.hAllows the delegate to provide a string to be edited as a proxy for the represented object.
- (NSString *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell editingStringForRepresentedObject:(id)representedObject
The token field cell that sent the message.
A represented object of the token field.
A string that’s an editable proxy of the represented object, or nil if the token should not be editable.
NSTokenFieldCell.hAllows the delegate to specify whether the represented object provides a menu.
- (BOOL)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell hasMenuForRepresentedObject:(id)representedObject
The token field cell that sent the message.
A represented object of the token field.
YES if the represented object has a menu, NO otherwise.
By default tokens have no menus.
NSTokenFieldCell.hAllows the delegate to provide a menu for the specified represented object.
- (NSMenu *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell menuForRepresentedObject:(id)representedObject
The token field cell that sent the message.
A represented object of the token field.
The menu associated with the represented object.
The returned menu should be autoreleased. By default tokens in a token field cell do not return menus.
NSTokenFieldCell.hAllows the delegate to return an array of objects representing the data read from pboard.
- (NSArray *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell readFromPasteboard:(NSPasteboard *)pboard
The token field cell that sent the message.
The pasteboard from which to read the represented objects.
An array of represented objects created from the pasteboard data.
NSTokenFieldCell.hAllows the delegate to provide a represented object for the string being edited.
- (id)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell representedObjectForEditingString:(NSString *)editingString
The token field cell that sent the message.
The edited string representation of a represented object.
A represented object that is displayed rather than the editing string.
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.
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. NSTokenFieldCell.hAllows the delegate to validate the tokens to be added to the receiver at a given index.
- (NSArray *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell shouldAddObjects:(NSArray *)tokens atIndex:(NSUInteger)index
The token field cell that sent the message.
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.
An array of validated tokens.
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.
NSTokenFieldCell.hAllows the delegate to return the token style for editing the specified represented object.
- (NSTokenStyle)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell styleForRepresentedObject:(id)representedObject
The token field cell that sent the message.
A represented object of the token field cell.
The style that should be used to display the representedObject. Possible values are shown in NSTokenStyle_Values.
If the delegate implements this method and returns an NSTokenStyle that differs from the style set by setTokenStyle:, the value the delegate returns is preferred.
If the delegate does not implement this method, the token field cell’s tokenStyle is used.
NSTokenFieldCell.hAllows the delegate the opportunity to write custom pasteboard types to the pasteboard for the represented objects in objects.
- (BOOL)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell writeRepresentedObjects:(NSArray *)objects toPasteboard:(NSPasteboard *)pboard
The token field cell that sent the message.
An array of represented objects associated with the token field cell.
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.
NSTokenFieldCell.hLast updated: 2009-05-06