Re: A rant and a question...
Re: A rant and a question...
- Subject: Re: A rant and a question...
- From: Nicko van Someren <email@hidden>
- Date: Sun, 30 Jul 2006 12:54:19 +0100
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:
This email sent to email@hidden