0

I'm trying add some addressbook functionality to my app, but after tap the second time to the 'Add to existing' button I get this error message.

* Assertion failure in -[ABPersonViewControllerHelper presentPeoplePickerNavigationControllerForAddToContacts:], /SourceCache/AddressBookUI_Sim/AddressBookUI-1118/ABPersonViewControllerHelper.m:2574 2011-10-24 20:41:11.960 locato[4576:11603] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Shouldn't be trying to show more than one Add to Existing Contact people picker.' First throw call stack: (0x152e052 0x16bfd0a 0x14d6a78 0xefd2db 0x9d674 0x152fe72 0xd0eb8 0xc8141 0xb9e2f 0x60471d 0x604952 0xe8c86d 0x1502966 0x1502407 0x14657c0 0x1464db4 0x1464ccb 0x17eb879 0x17eb93e 0x574a9b 0x22d9 0x2255) terminate called throwing an exception

I have a viewcontroller and a navigationcontroller, and im displaying the addressbook's 'modal' views on the main viewcontroller. (or else im not getting the sliding transition, and this error.). I have overridden these methods:

 @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];
}

Im hoping to get some clarification on what im not doing right!

thanks, David

david
  • 1
  • 1

1 Answers1

0

Two things you could change before trying again:

  • after both while loops, check that responder is not nil before doing dismiss or present a viewcontroller

  • can't you just assign screen.peoplePickerDelegate = self; instead of using this scr?

ott--
  • 5,554
  • 4
  • 22
  • 26
  • Thanks for trying to help, the responder is not nil, it is the main viewcontroller. The compiler gives me an error when im not using the 'scr' object because it thinks that the screen is a UIViewController instead of an ABPeoplePickerNavigationController.. I think the problem is that something is missing when im dismissing the ABPeoplePickerNavigationController.. but i cant figure out what is it.. – david Oct 25 '11 at 06:15
  • Can you show ABPersonViewControllerHelper.m around line 2574? And the other thing, does `[screen setPeoplePickerDelegate:self];` work? – ott-- Oct 25 '11 at 13:41
  • I cant show you the ABPersonViewControllerHelper.m because its in the AddressBookUI framework. And unfortunately `[screen setPeoplePickerDelegate:self];` doesnt work either because the compiler still thinks that screen is a uiviewcontroller. :( – david Oct 25 '11 at 14:05