Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting the contents of an NSTokenField programatically



Is there a sanctioned way to programatically set the contents of an NSTokenField (with contents that are tokens, not plain strings)? I want to preset the contents before the user sees the control, but I can't figure out a straightforward way to do it.

I feel like I must be missing something obvious, this must be supported via an API, yes?

[ tokenField setStringValue: @"blah" ] simply puts the string "blah" in the edit field, even if it should have matched a token from the delegate method tokenField:displayStringForRepresentedObject:. Presumably the delegate method is only called when the edit field changes due to user interaction, not a programatic setStringValue:.

I almost have something working by implementing the delegate method tokenField:readFromPasteboard: to do what I want and fake a "paste" call via [ [ tokenField currentEditor ] paste: nil ]. This allows me to populate the NSTokenField correctly, and the strings tokenize as expected, but now I need to be able to duplicate the default handling of tokenField:readFromPasteboard: for drag&drop to work correctly (of course), and I'm having difficulty implementing the default behavior. In any case, this can't be the expected way of accomplishing this; there must be a more straightforward way... right?

-- Tim Gogolin

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.