我想只显示那些有地址字段的联系人。我正在使用此代码..请帮助..
- (ABAddressBookRef)getValidAddress{
ABAddressBookRef allPeople = ABAddressBookCreate();
ABAddressBookRef contactsWithAddress = ABAddressBookCreate();
CFArrayRef allContacts = ABAddressBookCopyArrayOfAllPeople(allPeople);
CFIndex numberOfContacts = ABAddressBookGetPersonCount(allPeople);
CFErrorRef anError = NULL;
for(int i=0; i<numberOfContacts;i++){
ABRecordRef aPerson = CFArrayGetValueAtIndex(allContacts, i);
ABMultiValueRef AddressProperty = ABRecordCopyValue(aPerson, kABPersonAddressProperty);
if(ABMultiValueGetCount(AddressProperty)>0){
NSLog(@"this dude has address, he's on the list");
//ABAddressBookAddRecord(contactsWithEmail, aPerson, &anError);
}
else{
NSLog(@"this guy has no address, removing them from the addressBook");
ABAddressBookRemoveRecord(contactsWithAddress, aPerson, &anError);
}
}
return contactsWithAddress;
}
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
ABAddressBookRef test = [self getValidAddress];
[picker setAddressBook:test];
NSArray* emailProp = [NSArray arrayWithObjects:
[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonBirthdayProperty],
[NSNumber numberWithInt:kABPersonAddressProperty],
nil];;
picker.displayedProperties = emailProp;
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
//[parentController presentModalViewController:picker animated:YES];
[picker release];
}
现在它在选择器中显示联系人,但是现在我的输出是:
TEST1 44-541541-52 D-551,New York,TEST2 54-965684-85 j.V 街道印度,TEST3 95-95684-956 NIL,TEST3 20-95684-956 NIL,
现在我得到了这个输出:
TEST1 TEST2 TEST2 TEST2
请帮忙...... 它显示重复..
答案 0 :(得分:0)
恐怕你运气不好。 ABPeoplePickerController
是一个相当有限的课程。
您必须滚动自己的人员选择器控制器,并使用您迭代过滤过的地址簿中的所有记录填充它。
答案 1 :(得分:0)