how to search contact from address book using uitextview in iphone?
i'm using uitextview for searching the contact details from address book. i.e., like uisearchbar search the contact details while tex开发者_运维问答t edit change in uitextview.
i'm using uitextview if i tap 'a', the list of the contacts from address book will be display in table view
please give me the solution
Finally I got the solution simple coding here it is
//viewDidLoad
NSMutableArray *personArray = [[NSMutableArray alloc] init]; ABRecordRef personRef; for (int i = 0; i < CFArrayGetCount(allPeople); i++) { personRef = (ABRecordID*)CFArrayGetValueAtIndex(allPeople, i); ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, ABRecordGetRecordID(personRef)); @try { if (ABRecordCopyValue(person, kABPersonBirthdayProperty)) [personArray addObject: (id)personRef]; } @catch (NSException * e) { } @finally { } NSString *FirstName = [[[NSString stringWithString:(NSString *)ABRecordCopyValue(personRef, kABPersonFirstNameProperty)]stringByAppendingString:@" "]stringByAppendingString:(NSString *)ABRecordCopyValue(personRef, kABPersonLastNameProperty)]; [arr addObject:FirstName]; } [arr3 addObjectsFromArray:arr]; }
//textviewdidchange
[arr3 removeAllObjects]; NSInteger counter = 0; for(NSString *name in arr) { NSRange r = [name rangeOfString:txtView.text options:NSCaseInsensitiveSearch]; if(r.location != NSNotFound) { [arr3 addObject:name]; } counter++; } [table reloadData];
Thanks for your help
精彩评论