我希望我的用户通过从地址簿中选择联系人的电子邮件来填写电子邮件字段.我不希望他们滚动所有未设置电子邮件的联系人,所以我想过滤那些有电子邮件地址的联系人.
这是我到目前为止编写的代码.我可以找出谁有一个电子邮件地址,谁没有,但我不能告诉ABPeoplePickerNavigationController只列出正确的联系人.是不可能实现这一点,我的意思是我必须使用表格视图实现我自己的联系人选择器类或这段代码有什么问题吗?
ABAddressBookRef addressBook = ABAddressBookCreate(); NSArray *peopleList = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); NSLog(@"%ld people exist in the addressBook",ABAddressBookGetPersonCount(addressBook)); for (id peopleRecord in peopleList) { ABMultiValueRef mv = ABRecordCopyValue((ABRecordRef)peopleRecord,kABPersonEmailProperty); CFIndex numberOfAddresses = ABMultiValueGetCount(mv); if(numberOfAddresses == 0) { CFErrorRef err; ABAddressBookRemoveRecord( addressBook,(ABRecordRef)peopleRecord,&err); } } [peopleList release]; NSLog(@"%ld people have an email",ABAddressBookGetPersonCount(addressBook)); ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init]; NSNumber* emailProp = [NSNumber numberWithInt:kABPersonEmailProperty]; [peoplePicker setAddressBook:addressBook]; peoplePicker.displayedProperties = [NSArray arrayWithObject:emailProp]; [peoplePicker setPeoplePickerDelegate:self]; [self presentModalViewController:peoplePicker animated:YES];