- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
场景是我有多个 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/
场景是我有多个 View 想要调用地址簿。为了不在每个 View 中重复委托(delegate)的代码,我已将代码放在应用程序委托(delegate)的 header 和 .m 文件中,但在 2 个相
我是一名优秀的程序员,十分优秀!