我对iOS开发非常新颖。所以,请尽可能准确和基本地做出回应。如何告诉地址簿选择器填写哪些字段?
我有一个有两个(此时 - 可能会有更多)的字段,每个字段旁边都会有一个按钮,允许用户从iPad地址簿中选择一个联系人并填写相关字段和地址簿中的姓氏。
The example code I have拉去,我可以在联系人姓名填点。不过,我希望能够点击推荐人旁边的“浏览联系人”按钮,并使用相同的功能填写名称。我看到getContactName函数具有sender参数。所以,我可以很容易地判断两个按钮(或其他人)中的哪一个被点击。
但是,当我从地址簿中选择,我怎么知道在PeoplePickerNavigationController或fillContactName函数中点击了哪个按钮?
- (IBAction)getContactName:(id)sender {
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
[self fillContactName:person];
[self dismissModalViewControllerAnimated:YES];
return NO;
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
return NO;
}
- (void)fillContactName:(ABRecordRef)person
{
NSString* firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person,
kABPersonFirstNameProperty);
NSString *test = [firstName stringByAppendingString:@" "];
NSString* lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person,
kABPersonLastNameProperty);
NSString *fullName = [test stringByAppendingString:lastName];
self.contactName.text = fullName;
}
在附注中,您确定不想使用“ABRecordCopyCompositeName()”函数而不是手动将姓和名放在一起吗? – 2012-06-20 19:15:16