NSTokenField won't autocomplete non-alphanumeric chars
NSTokenField won't autocomplete non-alphanumeric chars
- Subject: NSTokenField won't autocomplete non-alphanumeric chars
- From: Mike Blaguszewski <email@hidden>
- Date: Mon, 27 Aug 2007 20:36:13 -0400
I'm trying to use an NSTokenField to enter email recipients, similar
to Mail.app. As the user types a name or email address, the token
field shows a menu of completions that I get from the system address
book. The problem is that when I type a non-alphanumeric character
like a space, or even "@", the token field chooses the currently
selected completion and closes the menu.
This is entirely independent of the -tokenizingCharacterSet option.
What I need is an -autocompleteCharacterSet option. Has anybody
managed to get NSTokenField to work with email addresses? Given that
even the documentation suggests using for this purpose, I'm quite
confused why it can't handle characters like "@".
Here's the simplified test app code: just a single delegate method.
- (NSArray *)tokenField:(NSTokenField *)tokenField
completionsForSubstring:(NSString *)substring
indexOfToken:(int)tokenIndex
indexOfSelectedItem:(int *)selectedIndex
{
NSArray *allAddresses;
NSMutableArray *matches;
int i;
allAddresses = [NSArray arrayWithObjects:@"email@hidden",
@"email@hidden",
nil];
// Find subset of allAddresses who have subString as a prefix
matches = [NSMutableArray array];
for (i = 0; i < [allAddresses count]; i++)
{
NSString *address = [allAddresses objectAtIndex:i];
if ([address rangeOfString:substring].location == 0)
{
[matches addObject:address];
}
}
return matches;
}
Thanks,
--
Mike Blaguszewski / Cocoa Hacker / Ambrosia Software, Inc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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