ABPersonCreate UINavigationController 按钮句柄

ABPersonCreate UINavigationController buttons handle

我有打开添加人员页面的代码,但是当我点击 "done" 或 "cancel" 按钮时没有任何反应。

我错过了什么?

我需要在用户点击 "done" 时保存到联系人列表,以及在 "cancel" 返回上一个视图时。

-(void)moveToAddContactButton
{
ABRecordRef newPerson= ABPersonCreate();
CFErrorRef error = NULL;

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);

NSString *phoneNumber =[NSString stringWithFormat:@"%@",theUser.symboNumber];

ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(phoneNumber), kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
NSAssert(!error, @"something bad happend here.");


ABNewPersonViewController* newPersonViewController = [[ABNewPersonViewController alloc] initWithNibName:nil bundle:nil];
[newPersonViewController setDisplayedPerson:newPerson];
[newPersonViewController setNewPersonViewDelegate:self];


UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:newPersonViewController];

[self presentViewController:navController animated:YES completion:nil];


CFRelease(newPerson);

}

我将表单 UINavigationController 更改为 ABPeoplePickerNavigationController,它解决了我的问题。

之后,我将 didCompleteWithNewPerson 添加到 handel tap on buttons。

-(void)moveToAddContactButton { ABRecordRef newPerson=ABPersonCreate(); CFErrorRef 错误 = NULL;

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);

NSString *phoneNumber =[NSString stringWithFormat:@"%@",theUser.symboNumber];

ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(phoneNumber), kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);

NSAssert(!error, @"something bad happend here.");


ABNewPersonViewController* newPersonViewController = [[ABNewPersonViewController alloc] initWithNibName:nil bundle:nil];
[newPersonViewController setDisplayedPerson:newPerson];
[newPersonViewController setNewPersonViewDelegate:self];


ABPeoplePickerNavigationController *navController = [[ABPeoplePickerNavigationController alloc] initWithRootViewController:newPersonViewController];

[self presentViewController:navController animated:YES completion:nil];


CFRelease(newPerson);

}

:

-(void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(ABRecordRef)person
{

[self dismissViewControllerAnimated:YES completion:nil];

}