我正在使用uitextview搜索地址簿中的联系方式。即,像uisearchbar一样在uitextview中搜索文本编辑时搜索联系人详细信息。
我正在使用uitextview如果点击“a”,地址簿中的联系人列表将显示在表格视图中
请给我解决方案
答案 0 :(得分:0)
最后我得到的解决方案是简单的编码,这是
// 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];
感谢您的帮助