如何绕过ABPeoplePickerNavigationController缺少"添加"按钮?

Mel*_*emi 3 iphone cocoa-touch addressbook

我的应用程序需要将自定义类的实例与iPhone的AddressBook中的联系人记录相关联.当我呈现ABPeoplePickerNavigationController并允许用户选择现有联系人时,一切都很好.问题是,有没有明显的方式,让用户可以轻松地添加一个联系人记录,如果他们正在寻找一个不已经在他们的通讯录存在.

人们如何以一种简单直观的方式从ABPeoplePickerNavigationControllerABNewPersonViewController

Sco*_*ood 6

您可以创建一个UIBarButton并将其添加到ABPeoplePickerNavigationController的UINavigationBar中.

    peoplePicker.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson:)];

-(IBAction)addPerson:(id)sender{
    ABNewPersonViewController *view = [[ABNewPersonViewController alloc] init];
    view.newPersonViewDelegate = self;
    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:view];
    [self.picker presentModalViewController:nc animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是ABPeoplePickerNavigationController有一个取消按钮放在rightBarButtonItem插槽中,我不得不更新导航栏上的

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
Run Code Online (Sandbox Code Playgroud)

我已经在我的博客上记录了整个过程,其中包含一个可以让您创建类似于iPhone上的联系人样式应用程序的工作示例.希望这可以帮助.