如何使用iphone中的uitextview从地址簿中搜索联系人?
问题描述:
我使用uitextview从通讯录中搜索联系人详细信息。即像uisearchbar一样搜索联系人详细信息,而在uitextview中进行文本编辑更改。如何使用iphone中的uitextview从地址簿中搜索联系人?
我使用的UITextView如果我点击“A”,从通讯录中的联系人列表将在表视图中显示
请给我解决
答
最后我得到了解决简单的编码这里是
// 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];
感谢您的帮助
你可能会得到更多的答案,如果你表明你写的代码,并详细说明什么是/不管用。 – Greg 2011-03-14 16:44:38
@GregInYEG:这里我添加了图片请确认 – Sri 2011-03-14 17:07:49
首先,点击iPhone(或任何没有鼠标的设备)是不可能的。其次,在Mac上制作屏幕截图时,使用⇧⌘4,然后按空格键。第三,[Three20](https://github.com/facebook/three20)有一个消息编辑器类。你可以看看它的源代码。 – 2011-03-14 17:08:17