Re: NSTokenField completion problems
Re: NSTokenField completion problems
- Subject: Re: NSTokenField completion problems
- From: Danny Hall <email@hidden>
- Date: Sat, 9 Jun 2007 12:49:08 -0400
I figured it out. Should anyone come across this, [tokenField
stringValue] returns some type of control character (0xfffc) - one
for every previous token in the field. I would expect it to return
the actual tokenizing character, but it doesn't. The character is not
logged in the description of the string (or is invisible), but a
length call to it reveals its presence.
I used
- (NSArray *)tokenField:(NSTokenField *)tokenField
completionsForSubstring:(NSString *)substring indexOfToken:(int)
tokenIndex indexOfSelectedItem:(int *)selectedIndex{
NSString *fieldString = [tokenField stringValue];
while([fieldString characterAtIndex:0] == 0xfffc){
fieldString = [fieldString substringFromIndex:1];
}
to get rid of it so I could perform the matching against my possible
return values. Now if I could just find a way to intercept the space
keypress that the autocompletion menu treats as a menu item
selection, and pass it to the token field as a space character, I'd
be set. But that I can live with.
Cheers.
On Jun 8, 2007, at 7:55 PM, Danny Hall wrote:
Greetings
I am using NSTokenField the same way that Mail.app does. I'm
linking against the AddressBook frameworks and implementing the
NSTokenField delegate method
tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:.
I retrieve matches from AB for the substring entered by the user
and format the matches into an array of possible patterns: (first,
last, email) or (email, first, last), etc. Then I compare these
items against the value of the token field that I am passed using
[tokenField stringValue], to make sure I only return strings that
begin with what is already in the token field.
This works fine for the first token, but every subsequent token
refuses to match valid the current token field string value to the
array of items retrieved from the AddressBook database.
The run log shows the address records are retrieved and formatted,
and the string I am trying to match, but for whatever reasons valid
matches won’t match no matter what method I try.
First token:
===== MATCHED ====== "Fred Smith <xxxxxxxxx>" does contain "Fred"
Second token:
===== No match ====== "Fred Smith <xxxxxxxxx>" does NOT contain "Fred"
I’ve tried
commonPrefixWithString:options:
compare:options:range:
rangeOfString:
As well as, copying the strings first, transforming to c strings,
then back again, and making new strings with “stringWithFormat”.
If insert a dummy line
Return [NSArray arrayWithObjects:@”1”, @”2”, @’3”, niil];
At the beginning of the delegate method, it works great for every
token, so I know the problem is something is screwey about the
string passed to me from the token field.
I’m stuck. Has anyone seen behavior like this, or can someone offer
pointers?
Thanks
Danny_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden