Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS 6通过ABPeoplePickerNavigationController创建新联系人_Ios_Addressbook_Addressbookui - Fatal编程技术网

iOS 6通过ABPeoplePickerNavigationController创建新联系人

iOS 6通过ABPeoplePickerNavigationController创建新联系人,ios,addressbook,addressbookui,Ios,Addressbook,Addressbookui,我正试图遵循苹果的通讯录编程指南,对peoplePickerController有疑问。苹果教程中的示例照片右上角有一个“plus”按钮,似乎可以让用户通过peoplePickerController添加新联系人 我打电话给ABPeopleNavigationControllerPicker通过 - (void)showPicker { ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationCont

我正试图遵循苹果的通讯录编程指南,对peoplePickerController有疑问。苹果教程中的示例照片右上角有一个“plus”按钮,似乎可以让用户通过peoplePickerController添加新联系人

我打电话给ABPeopleNavigationControllerPicker通过


- (void)showPicker
{
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;

    [self presentViewController:picker animated:YES completion:nil];
}
但屏幕右上角有一个取消按钮,而不是加号按钮。是否有任何选项可以更改按钮或允许用户通过此视图控制器添加新联系人

在谷歌搜索了很长一段时间后,下面是我发现的。所以我试着用编程的方式改变这个按钮


-(无效)某人
{
ABNewPersonViewController*newPersonVC=[[ABNewPersonViewController alloc]init];
newPersonVC.newPersonViewDelegate=self;
UINavigationController*nc=[[UINavigationController alloc]initWithRootViewController:newPersonVC];
[自呈现视图控制器:nc动画:是完成:无];
}
-(void)showPicker
{
ABPeoplePickerNavigationController*picker=[[ABPeoplePickerNavigationController alloc]init];
picker.topViewController.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarbuttonSystemAddTarget:self action:@selector(addPerson)];
picker.peoplePickerDelegate=self;
[自我呈现视图控制器:选择器已设置动画:是完成:无];
}


然而,不知何故,工具栏按钮仍然被固定为“取消”而不是“添加”…

没关系,我现在让它工作了。似乎我需要在覆盖其按钮之前显示ViewController


-(void)showPicker
{
ABPeoplePickerNavigationController*picker=[[ABPeoplePickerNavigationController alloc]init];
picker.peoplePickerDelegate=self;
[自我呈现视图控制器:选择器已设置动画:是完成:无];
[picker.topViewController设置编辑:是];
picker.topViewController.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarbuttonSystemAddTarget:self action:@selector(addPerson)];
}

在iOS 7上,我需要稍后设置这些按钮

 - (void)showPicker
 {
     ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
      picker.peoplePickerDelegate = self;
     [self presentViewController:picker animated:YES completion:nil];
   [picker.topViewController setEdit:YES];
   [self performSelector:@selector(setThemBuddons:) withObject:picker afterDelay:0.1];
}

-(void)setThemBuddons:(ABPeoplePickerNavigationController*)picker;
{
     picker.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson)];

}

您只需要对addPerson方法进行一个小的修改

用于显示联系人:

-(void)showPicker

{

}

-(void)addContact:(ABPeoplePickerNavigationController*)选择器

{

}

通过此代码,您将在右上角获得一个加号以添加联系人

我们正在为此使用@selector

-(无效)某人

{

//这是执行该工作的代码行。通过使用self.presentedViewController,我们可以//获得添加联系人屏幕,否则我们将得到类似空视图层次结构的错误

    [self.presentedViewController presentViewController:nc animated:YES completion:nil];

}

值得一提的是,苹果自己的示例(在iOS通讯录编程指南中链接到)也有相同的“取消”按钮。这是正确的。不知何故,我也需要对我的iOS7应用程序进行修改。感谢您的提示。您可以在presentViewController方法调用中使用完成块,而不是添加延迟。还有,为什么不把按钮放在左边,让用户用右边的默认按钮取消呢?
 - (void)showPicker
 {
     ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
      picker.peoplePickerDelegate = self;
     [self presentViewController:picker animated:YES completion:nil];
   [picker.topViewController setEdit:YES];
   [self performSelector:@selector(setThemBuddons:) withObject:picker afterDelay:0.1];
}

-(void)setThemBuddons:(ABPeoplePickerNavigationController*)picker;
{
     picker.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson)];

}
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController       alloc] init];
  picker.peoplePickerDelegate = self;
  [self presentViewController:picker animated:YES completion:nil];
  [picker.topViewController setEdit:YES];
  [self performSelector:@selector(addContact:) withObject:picker afterDelay:0.1];
picker.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson)];
ABNewPersonViewController *newPersonVC = [[ABNewPersonViewController 
alloc] init];
newPersonVC.newPersonViewDelegate = self;
UINavigationController *nc = [[UINavigationController alloc]     initWithRootViewController:newPersonVC];
    [self.presentedViewController presentViewController:nc animated:YES completion:nil];