0

我在网上找到了一个教程,它扩展了 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;

}

如何确保标签是用户选择的标签,而不仅仅是第一个数组条目(或我编码的任何其他数组条目)

谢谢

4

1 回答 1

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

我没有遵循您的代码片段 - 如果您想要的只是用户选择的选择,则不确定您使用数组的目的。

于 2010-03-27T03:36:40.047 回答