Mac Developer Library

Developer

AppKit Framework Reference NSTokenFieldCellDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSTokenFieldCellDelegate

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.6 and later.

The NSTokenFieldCellDelegate protocol defines the optional methods implemented by delegates of NSTokenFieldCell objects.

  • Allows the delegate to provide a string to be displayed as a proxy for the represented object.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, displayStringForRepresentedObject representedObject: AnyObject) -> String?

    Objective-C

    - (NSString *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell displayStringForRepresentedObject:(id)representedObject

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    representedObject

    A represented object of the token field cell.

    Return Value

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate to return the token style for editing the specified represented object.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, styleForRepresentedObject representedObject: AnyObject) -> NSTokenStyle

    Objective-C

    - (NSTokenStyle)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell styleForRepresentedObject:(id)representedObject

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    representedObject

    A represented object of the token field cell.

    Return Value

    The style that should be used to display the representedObject. Possible values are shown in NSTokenStyle_Values.

    Discussion

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate to provide an array of appropriate completions for the contents of the receiver.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, completionsForSubstring substring: String, indexOfToken tokenIndex: Int, indexOfSelectedItem selectedIndex: UnsafeMutablePointer<Int>) -> [AnyObject]

    Objective-C

    - (NSArray *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    substring

    The partial string that is to be completed.

    tokenIndex

    The index of the token being edited.

    selectedIndex

    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.

    Return Value

    An array of strings that are possible completions.

    Discussion

    If the delegate does not implement this method, no completions are provided.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate to provide a string to be edited as a proxy for the represented object.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, editingStringForRepresentedObject representedObject: AnyObject) -> String?

    Objective-C

    - (NSString *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell editingStringForRepresentedObject:(id)representedObject

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    representedObject

    A represented object of the token field.

    Return Value

    A string that’s an editable proxy of the represented object, or nil if the token should not be editable.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate to provide a represented object for the string being edited.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, representedObjectForEditingString editingString: String) -> AnyObject

    Objective-C

    - (id)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell representedObjectForEditingString:(NSString *)editingString

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    editingString

    The edited string representation of a represented object.

    Return Value

    A represented object that is displayed rather than the editing string.

    Discussion

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate to validate the tokens to be added to the receiver at a given index.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, shouldAddObjects tokens: [AnyObject], atIndex index: Int) -> [AnyObject]

    Objective-C

    - (NSArray *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell shouldAddObjects:(NSArray *)tokens atIndex:(NSUInteger)index

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    tokens

    An array of tokens to be inserted in the receiver at index.

    index

    The index of the receiver in which the array of tokens to be validated (tokens) will be inserted.

    Return Value

    An array of validated tokens.

    Discussion

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate to return an array of objects representing the data read from pboard.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, readFromPasteboard pboard: NSPasteboard) -> [AnyObject]?

    Objective-C

    - (NSArray *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell readFromPasteboard:(NSPasteboard *)pboard

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    pboard

    The pasteboard from which to read the represented objects.

    Return Value

    An array of represented objects created from the pasteboard data.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate the opportunity to write custom pasteboard types to the pasteboard for the represented objects in objects.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, writeRepresentedObjects objects: [AnyObject], toPasteboard pboard: NSPasteboard) -> Bool

    Objective-C

    - (BOOL)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell writeRepresentedObjects:(NSArray *)objects toPasteboard:(NSPasteboard *)pboard

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    objects

    An array of represented objects associated with the token field cell.

    pboard

    The pasteboard to which to write the represented objects.

    Return Value

    YEStrue if the delegate writes the represented objects to the pasteboard, NOfalse otherwise. If NOfalse, the token field writes the display strings to the NSStringPboardType pasteboard.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate to specify whether the represented object provides a menu.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, hasMenuForRepresentedObject representedObject: AnyObject) -> Bool

    Objective-C

    - (BOOL)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell hasMenuForRepresentedObject:(id)representedObject

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    representedObject

    A represented object of the token field.

    Return Value

    YEStrue if the represented object has a menu, NOfalse otherwise.

    Discussion

    By default tokens have no menus.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate to provide a menu for the specified represented object.

    Declaration

    Swift

    optional func tokenFieldCell(_ tokenFieldCell: NSTokenFieldCell, menuForRepresentedObject representedObject: AnyObject) -> NSMenu?

    Objective-C

    - (NSMenu *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell menuForRepresentedObject:(id)representedObject

    Parameters

    tokenFieldCell

    The token field cell that sent the message.

    representedObject

    A represented object of the token field.

    Return Value

    The menu associated with the represented object.

    Discussion

    The returned menu should be autoreleased. By default tokens in a token field cell do not return menus.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.