0

タップすると連絡先リストが表示され、選択した電話番号が uitextfield に追加される uibutton があります。使用しているコードは次のとおりです。

- (IBAction)contact1:(id)sender
{
ABPeoplePickerNavigationController *picker1 =
[[ABPeoplePickerNavigationController alloc] init];
picker1.peoplePickerDelegate = self;
[self presentModalViewController:picker1 animated:YES];
}
- (void)peoplePickerNavigationControllerDidCancel:

(ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissModalViewControllerAnimated:YES];
 }
 - (BOOL)peoplePickerNavigationController:

 (ABPeoplePickerNavigationController *)peoplePicker 
  shouldContinueAfterSelectingPerson:(ABRecordRef)person {
  [self displayPerson:person];
  [self dismissModalViewControllerAnimated:YES];
  return NO;
  }


 - (BOOL)peoplePickerNavigationController:

 (ABPeoplePickerNavigationController *)peoplePicker
 shouldContinueAfterSelectingPerson:(ABRecordRef)person
 property:(ABPropertyID)property
 identifier:(ABMultiValueIdentifier)identifier

 {
 return NO;
 }

- (void)displayPerson:(ABRecordRef)person
 {
NSString* phone = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0) {
    phone = (__bridge_transfer NSString*)
    ABMultiValueCopyValueAtIndex(phoneNumbers, 0);

 } else {
    phone = @"[None]";
    }
 self.telField1.text = phone;
 }

私がやろうとしているのは、複数の uibuttons に電話番号を複数の uitextfield に追加させることです。

例: contact1 ボタンは phone# を telField1 に追加します contact2 ボタンは phone# を telField2 に追加します contact3 ボタンは phone# を telField3 に追加します

各テキストフィールドには異なる電話番号があります。

元のコードを微調整できますか、それとも別の方法を試す必要がありますか?

4

1 に答える 1

1
-(IBAction)getContact {
// creating the picker
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
// place the delegate of the picker to the controll
picker.peoplePickerDelegate = self;

// showing the picker
[self presentModalViewController:picker animated:YES];
// releasing
[picker release];

}

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
// assigning control back to the main controller
[self dismissModalViewControllerAnimated:YES];

}

  - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

// setting the first name
firstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

// setting the last name
lastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);   

ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
number.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);

// remove the controller
[self dismissModalViewControllerAnimated:YES];

return NO;

}

  - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
return NO;

}

ボタンをクリックするだけでテキストフィールドに連絡先が表示されます。テキストフィールドごとに個別のボタンを設定する必要はありません。

于 2012-10-25T05:47:58.283 に答える