views:

380

answers:

1

Hey guys!
I want to build a NSTokenField that works just like the recipient field in Mail.app. I know how to search the address book for names and emails. These are probably really bad noob questions, sorry for that.

  1. How can I reformat my search results array to get items in the format "Name <email>" (like the auto completion results in Mail.app)

  2. How does the NSTokenField Completion method work? I can't find a code example that works for me. Can you explain it or give me some code?

+1  A: 

It's been a while since I used NSTokenField but here it goes:

Ad. 2. you have a method of NSTokenField delegate called tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: which should return an array of possible competitions of provided substring. The way it works is that you set your class as a delegate of your NSTokenField and override that method and in it you search your database for records that matches provided substring and return an array of possible matches. The cocoa should do the rest.

Ad. 1. once again NSTokenField delegate can have method called tokenField:displayStringForRepresentedObject: which allows you to display the some object (like email address) with any format you want (so the object would be just email and you might return string in a format "Name " from that method by finding name for that particular email in your database).

Hope that helps!

shw