如果文本本身无法更改且需要更换按钮,那么请解释如何制作委托方法
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
仍然可以从替换按钮调用吗?
非常感谢任何帮助。
答案 0 :(得分:2)
经过一番摆弄后,这有效:
在对象UINavigationControllerDelegate
文件中包含.h
。将以下内容添加到.m
文件中:
- (void) showAddressBook {
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
// use delegate to change cancel text to done on picker that pops up
picker.delegate = self;
[self presentViewController:picker animated:true completion:nil];
}
// replace button now that controller is initialized
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if([navigationController isKindOfClass:[ABPeoplePickerNavigationController class]]) {
UIBarButtonItem *obbi = navigationController.topViewController.navigationItem.rightBarButtonItem;
UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:obbi.target action:obbi.action];
navigationController.topViewController.navigationItem.rightBarButtonItem = bbi;
}
}