Mailing Lists: Apple Mailing Lists

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

Re: A rant and a question...



On 25 Jul 2006, at 15:57, Brad Bumgarner wrote:

I want to be able to type a person's name, first name first --or-- last name first, --or-- type in a company name and have a menu of all available matches displayed and narrowed down as typing continues.

Sounds like you need to use ABSearchElement +searchElementForConjunction:children, e.g.


- (NSArray *) searchForSubstring: (NSString *) sub {
first = [ABPerson searchElementForProperty: kABFirstNameProperty
label: nil key: nil value: sub comparison: kABPrefixMatchCaseInsensitive];
last = [ABPerson searchElementForProperty: kABLastNameProperty
label: nil key: nil value: sub comparison: kABPrefixMatchCaseInsensitive];
company = [ABPerson searchElementForProperty: kABOrganizationProperty
label: nil key: nil value: sub comparison: kABPrefixMatchCaseInsensitive];


fullSearch = [ABSearchElement searchElementForConjunction: kABSearchOr children: [NSArray arrayWithObjects: first, last, company, nil];

return [[NSAddressBook sharedAddressBook] recordsMatchingSearchElement: fullSearch];
}


Call this from the tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: delegate method of your NSTokenField and extract some suitable representation of the people who match to display as possible completions. Note that you'll need to be careful how you return the matched name. When you return matches against a substring of length n it will replace the substring with the first n characters of the selected match. If the you matched 'blo' against "Fred Bloggs" then the 'blo' will be replaces with 'Fre' and when the next letter is typed the search substring will be 'Freg' not 'blog'. To fix this you have to return "Bloggs, Fred". This will be more complex when you are trying to match company names; when matching 'appl' you'll need to return something like "Apple: Fred Bloggs" for things to work out correctly.

	Nicko

_______________________________________________
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
References: 
 >A rant and a question... (From: Brad Bumgarner <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.