| OS X - Development and Darwin Discussion and questions about development for Mac OS X. |
| Post Reply | New Thread | Subscribe |
|
|
Thread Tools |
![]() Member Since: Jan 14, 2011
Posts: 1
![]() |
Hi guys, thanks for taking the time to at least read this far, this has been driving me nuts.
I'm having a problem with predictive text. I'm sure it's a dumb one that people far smarter than me can figure out quickly, but I just don't get it, at all. If my address book has the names David Smith, and Richard Smidgens, if I type in the characters "Sm", it behaves properly, seemingly, and shows both names, as options. The problem is that it's actually populated the field with the first two letters of the first name it's found. If I type in a third letter "i", instead of it keeping both name (Smith/Smidgens), it actually adds the i, to the first two letters of the first name, giving me "Dai", and removing the two names from contention for predictability. Any idea what I'm doing wrong here? Here's the code for this section Any help would be greatly appreciated... -Phil (The code is below) --- /** Creates the array of items used in the combo box of search results. */ - (NSArray*) createMatchesText: (NSArray*) searchResults { NSMutableArray* matchesArray = [NSMutableArray array]; size_t i; for (i = 0; i < [searchResults count]; ++i) { id obj = [searchResults objectAtIndex: i]; NSString* first = 0; NSString* last = 0; NSString* email = 0; @try { first = [obj valueForProperty: @"First"]; } @catch (NSException* e) { } @try { last = [obj valueForProperty: @"Last"]; } @catch (NSException* e) { } @try { id emails = [obj valueForProperty: @"Email"]; if (emails) { NSString* primaryId = [emails primaryIdentifier]; int index = [emails indexForIdentifier:primaryId]; email = [(ABMultiValue*)emails valueAtIndex: index]; } } @catch (NSException* e) { } NSMutableString* str = [[NSMutableString alloc] init]; if (first) { [str appendString: first]; } if (last) { [str appendString: [NSString stringWithFormat: @" %@", last]]; } if (email) { [str appendString: [NSString stringWithFormat: @" <%@>", email]]; } [matchesArray addObject: str]; } return matchesArray; } - (NSArray *)tokenFieldCell: (NSTokenFieldCell*)tokenFieldCell completionsForSubstring: (NSString*)substring indexOfToken: (long)tokenIndex indexOfSelectedItem: (long*)selectedIndex { // See if anything matches in the address book ABAddressBook* ab = [ABAddressBook sharedAddressBook]; NSMutableArray* elms = [[NSMutableArray alloc] init]; ABSearchElement* firstName = [ABPerson searchElementForProperty:kABFirstNameProperty label:nil key:nil value: substring comparison: kABPrefixMatchCaseInsensitive]; ABSearchElement* lastName = [ABPerson searchElementForProperty:kABLastNameProperty label:nil key:nil value: substring comparison: kABPrefixMatchCaseInsensitive]; ABSearchElement* email = [ABPerson searchElementForProperty:kABEmailProperty label:nil key:nil value: substring comparison: kABPrefixMatchCaseInsensitive]; [elms addObject: firstName]; [elms addObject: lastName]; [elms addObject: email]; ABSearchElement* searchElm = [ABSearchElement searchElementForConjunction:kABSearchOr children:elms]; NSArray* searchResults = [[ab recordsMatchingSearchElement:searchElm] retain]; NSArray* matches = [self createMatchesText: searchResults]; if ([matches count] > 0) { *selectedIndex = 0; } else { *selectedIndex = -1; } return matches; } - (NSTokenStyle)tokenFieldCell: (NSTokenFieldCell *)tokenFieldCell styleForRepresentedObject: (id)representedObject { return NSPlainTextTokenStyle; } |
| QUOTE Thanks | |
| Post Reply | New Thread | Subscribe |
| Thread Tools | |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
|||||||
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Problem setting up email alarm in iCal | Mikethebook | OS X - Apps and Games | 8 | 06-01-2012 02:52 AM |
| random problem with safari text | b.lang | OS X - Apps and Games | 2 | 05-09-2010 05:18 PM |
| Forwarding email: Pictures portion don't send, only text? | GRRunner | Running Windows (or anything else) on your Mac | 2 | 01-06-2010 02:56 PM |
| Problem attaching files for email | krimedog | OS X - Apps and Games | 2 | 01-13-2008 04:35 PM |
| Text and video problem | Macca88 | Apple Notebooks | 0 | 12-13-2006 10:04 AM |
All times are GMT -4. The time now is 01:57 AM.
Powered by vBulletin