我正在尝试遵循 Apple 的地址簿编程指南,并对 peoplePickerController 有疑问。Apple 教程中的示例照片在右上角有“加号”按钮,这似乎允许用户通过 peoplePickerController 添加新联系人。
我通过调用 ABPeopleNavigationControllerPicker
- (void)showPicker
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
但是屏幕右上角有一个取消按钮,而不是加号按钮。是否有任何选项可以更改按钮或允许用户通过此视图控制器添加新联系人?
在谷歌搜索了一段时间后,我找到了以下内容。所以我尝试以编程方式更改栏按钮......
- (void)addPerson
{
ABNewPersonViewController *newPersonVC = [[ABNewPersonViewController alloc] init];
newPersonVC.newPersonViewDelegate = self;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:newPersonVC];
[self presentViewController:nc animated:YES completion:nil];
}
- (void)showPicker
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson)];
picker.peoplePickerDelegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
但是,不知何故,栏按钮仍然固定为“取消”而不是“添加”......