我试图在我的应用程序中添加一些地址簿功能,但在第二次点击"添加到现有"按钮后,我得到这个错误信息。
* assert failure in -[ABPersonViewControllerHelper presentPeoplePickerNavigationControllerForAddToContacts:],/SourceCache/AddressBookUI_Sim/AddressBookUI-1118/ABPersonViewControllerHelper.m:25742011-10-24 20:41:11.960 locato[4576:11603]终止应用程序由于未捕获异常'NSInternalInconsistencyException',原因:'不应该试图显示多个添加到现有联系人选择器'。第一个抛出调用栈:(0x152e052 0x16bfd0a 0x14d6a78 0x9d2db 0x9d674 0x152fe72 0xd0eb8 0xc8141 0xb9e2f 0x60471d 0x604952 0xe8c86d 0x1502966 0x1502407 0x14657c0 0x1464db4 0x1464ccb 0x17eb879 0x17eb93e 0x574a9b 0x22d9 0x2255)终止调用,抛出异常
我有一个视图控制器和一个导航控制器,我在主视图控制器上显示地址簿的'modal'视图。(否则我不能得到滑动过渡,和这个错误。)我重写了这些方法:
@implementation UIViewController (cancelButton)
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker;
{
UIResponder *responder = self;
while (responder && ![responder isKindOfClass:[mainViewController class]]) {
responder = [responder nextResponder];
}
[(UIViewController *)responder dismissModalViewControllerAnimated:YES];
}
@end
@implementation UINavigationController (modal)
- (void) presentModalViewController:(UIViewController *)screen animated:(BOOL)animated
{
UIResponder *responder = self;
while (responder && ![responder isKindOfClass:[mainViewController class]]) {
responder = [responder nextResponder];
}
if ([screen isKindOfClass:[ABPeoplePickerNavigationController class]]) {
ABPeoplePickerNavigationController *scr = screen;
scr.peoplePickerDelegate = self;
[scr release];
}
[(UIViewController *)responder presentModalViewController:screen animated:YES];
}
我希望得到一些澄清我做错了什么!
谢谢,大卫。
在再次尝试之前可以更改两件事:
-
在两个
while
循环之后,检查响应者不是nil
,然后进行解散或呈现视图控制器 -
你不能直接分配
screen.peoplePickerDelegate = self;
而不是使用这个scr吗?