gpt4 book ai didi

ios - 为什么 peoplePickerDelegate 没有正确获取代表的地址?

转载 作者:行者123 更新时间:2023-11-29 04:53:52 31 4
gpt4 key购买 nike

场景是我有多个 View 想要调用地址簿。为了不在每个 View 中重复委托(delegate)的代码,我已将代码放在应用程序委托(delegate)的 header 和 .m 文件中,但在 2 个相应应用程序的底部使用“@interface AddressBookDelegate”和“@implementation AddressBookDelegate”代表FIIES-

@interface AddressBookDelegate : UIViewController <ABPeoplePickerNavigationControllerDelegate> {
AddressBookDelegate *addressBookDelegate;
}
@property (nonatomic, retain) AddressBookDelegate *addressBookDelegate;
@end

@implementation AddressBookDelegate
@synthesize addressBookDelegate;

- (void)peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissModalViewControllerAnimated:YES];
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
[super dismissModalViewControllerAnimated:YES];

...get stuff from the Address Book...

return NO;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
return NO;
}

然后在我看来我有以下代码:

addressBookDelegate = (AddressBookDelegate *) [[UIApplication sharedApplication] delegate];

ABPeoplePickerNavigationController *abPicker = [[ABPeoplePickerNavigationController alloc]init];
abPicker.peoplePickerDelegate = self.addressBookDelegate;
[self presentModalViewController:abPicker animated:YES];
[abPicker release];

地址簿在所有 View 中都显示良好。但是,当我执行任何会调用委托(delegate)的用户操作(例如地址簿的取消按钮)时,我会崩溃 -

-[MyprogAppDelegate peoplePickerNavigationControllerDidCancel:]: unrecognized selector sent to instance

它编译干净,没有警告。

当 peoplePickerDelegate 与 View 本身不在物理上位于同一文件中时,如何连接 peoplePickerDelegate 以连接到地址委托(delegate)代码?谢谢。

添加注释:当我使用调试器并在线停止时

abPicker.peoplePickerDelegate = addressBookDelegate;

在 View 代码中,我看到addressBookDelegate的地址被声明为MyprogAppDelegate的地址,而不是我所期望的AddressBookDelegate的地址。这让我认为地址簿委托(delegate)代码的位移在应用程序委托(delegate)文件中已关闭。

如果AddressBookDelegate取消委托(delegate)代码在AddressBookDelegate中输入1000字节,我的应用程序实际上是将1000字节代码“输入”到MyprogAppDelegate中,因此崩溃。所以不知何故我没有正确设置 AddressBookDelegate 的寻址。无论如何,这就是我的看法......

最佳答案

您的代码假定您的 appdelegate (MyprogAppDelegate) 实现方法 peoplePickerNavigationControllerDidCancel

所以,MyprogAppDelegate 中的代码应该是这样的:

@implementation MyprogAppDelegate
@synthesize ...;

#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


return YES;
}

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{

}

关于ios - 为什么 peoplePickerDelegate 没有正确获取代表的地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8354247/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com