我在网上发现了一个教程,它扩展了Apple QuickStart应用程序,它是基本的地址簿应用程序,另一个则返回第一个电话号码,无论点击了哪个电话号码。我想只在标签中显示所选的电话号码。该标签名为phoneNumber:
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier{
ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSMutableArray *phones = [[NSMutableArray alloc] init];
int i;
for (i = 0; i < ABMultiValueGetCount(phoneMulti); i++) {
NSString *aPhone = [(NSString*)ABMultiValueCopyValueAtIndex(phoneMulti, i)autorelease];
[phones addObject:aPhone];
}
NSString *mobileNo = [phones objectAtIndex:0];
self.phoneNumber.text = phones;
[self dismissModalViewControllerAnimated:YES];
return NO;
}
如何确保标签是用户选择的标签,而不仅仅是第一个数组条目(或我编码的任何其他数组条目)
由于
答案 0 :(得分:2)
我不确定我理解你的问题,但是如果你想要获得电话号码和/或标签你的用户实际被选中,你可以使用它:
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
// ensure user picked a phone property
if (property == kABPersonPhoneProperty) {
ABMultiValueRef phone = ABRecordCopyValue(person, property);
CFStringRef selectedNumber = ABMultiValueCopyLabelAtIndex(phone, identifier);
CFStringRef selectedLabel = ABMultiValueCopyValueAtIndex(phone, identifier);
// insert code to do something with the values above
[self dismissModalViewControllerAnimated:YES];
return NO; } // end if
else {
// display an alert or something - handle the error
} } // end else, end method
我没有关注你的代码片段 - 如果你想要的只是用户的选择,不确定你使用的数组是什么。