ABPeoplePicker中的奇怪崩溃

时间:2011-01-27 07:27:55

标签: iphone objective-c cocoa-touch abpeoplepickerview

我正在使用ABPeoplePicker而且我遇到了一个奇怪的崩溃:

Assertion failure in -[UISearchDisplayController setActive:animated:], 
/SourceCache/UIKit/UIKit-1447.6.4/UISearchDisplayController.m:589
2011-01-26 22:30:37.041 Watches[3784:307] 
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'search contents navigation controller must not change between -setActive:YES and -setActive:NO

在用户使用搜索字段然后选择结果候选者之后发生崩溃。我的代理人的peoplePickerNavigationController:shouldContinueAfterSelectingPerson:方法  用一个人的适当信息调用。委托本身就是一个模态控制器,因此它将信息和调用保存回其父节点,调用[self dismissModalViewControllerAnimated:NO],然后将堆栈返回到ABPeoplePicker,为shouldContinue返回NO。

在ViewWillAppear中将断点设置为父例程(高水位线),我看到一个看起来像的堆栈:

#0  -[RunnerListTableViewController viewWillAppear:] (self=0x1cc650, _cmd=0x33bc6b5a, animated=1 '\001') at /Users/hughmackworth/develop/Watches/RunnerListTableViewController.m:61
#1  0x338e4fe4 in -[UINavigationController viewWillAppear:] ()
#2  0x3391a1e2 in -[UITabBarController viewWillAppear:] ()
#3  0x3396e280 in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] ()
#4  0x339dd36e in -[UIViewController _dismissModalViewControllerWithTransition:from:] ()
#5  0x339dc86e in -[UIViewController dismissModalViewControllerWithTransition:] ()
#6  0x339dc734 in -[UIViewController dismissModalViewControllerWithTransition:] ()
#7  0x339dc734 in -[UIViewController dismissModalViewControllerWithTransition:] ()
#8  0x339da668 in -[UIViewController dismissModalViewControllerAnimated:] ()
#9  0x000098c2 in -[RunnerListTableViewController runnerAddViewController:didAddRunners:] (self=0x1cc650, _cmd=0x29a86, runnerAddViewController=0x1dbf50, runners=0x45cb860) at /Users/hughmackworth/develop/Watches/RunnerListTableViewController.m:147
#10 0x0000d4a8 in -[RunnerAddNewViewController save:] (self=0x1dbf50, _cmd=0x3530e35b, runner=0x45c8c20) at /Users/hughmackworth/develop/Watches/RunnerAddNewViewController.m:174
#11 0x0000ce6c in -[RunnerAddNewViewController peoplePickerNavigationController:shouldContinueAfterSelectingPerson:] (self=0x1dbf50, _cmd=0x30549382, peoplePicker=0x35c87e0, person=0x455f2c0) at /Users/hughmackworth/develop/Watches/RunnerAddNewViewController.m:105
#12 0x35eabaea in -[ABPeoplePickerNavigationController showCardForPerson:withMemberCell:animate:forceDisableEditing:personViewController:] ()
#13 0x35eab978 in -[ABMembersViewController showCardForPerson:withMemberCell:animate:] ()
#14 0x35eab826 in -[ABMembersController showCardForPerson:withMemberCell:animate:] ()
#15 0x35eab76a in -[ABMembersController abDataSource:selectedPerson:atIndexPath:withMemberCell:animate:] ()
#16 0x35eab70e in -[ABMembersFilteredDataSource tableView:didSelectRowAtIndexPath:] ()
#17 0x3390483a in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] ()
#18 0x339c4612 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:] ()

然后我看着各种例程结束,直到它堆叠到达时崩溃:

// removed assertion handling routines>>
4   UIKit              0x3394192b -[UISearchDisplayController setActive:animated:] + 986
5   AddressBookUI      0x35ee65d7 -[ABMembersController cancelSearchingAnimated:] + 26
6   AddressBookUI      0x35eab789 -[ABMembersController abDataSource:selectedPerson:atIndexPath:withMemberCell:animate:] + 80
7   AddressBookUI      0x35eab70f -[ABMembersFilteredDataSource tableView:didSelectRowAtIndexPath:] + 82
8   UIKit              0x3390483b -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 662

这一切对我来说都是完全正确的,除了断言崩溃之外。

由于我与ABPeoplePicker内部的搜索控制器无关,也没有在它变为活动状态期间进行更改,我看不出如何解决这个问题。

作为旁注,我确实注意到一个偶然的错误: CPSqliteStatementSendResults:中断,当我在搜索框中输入内容时。对这意味着什么的想法?

代表的代码是:

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    NSLog(@"got one from peoplepicker");
    if (ABRecordGetRecordType (person) == kABPersonType{ 

    Runner * newRunner = [Runner createRunnerFromAddrBookPerson: person];
    if (newRunner) {
            self.nameTextView.text = newRunner.Name;
            [self save:newRunner];
    }
    return NO;    //EDIT: MUST return YES or this will crash
}

- (void)save: (Runner *) runner { //send back last one added
    [self.delegate runnerAddViewController:self 
                             didAddRunners:[NSArray arrayWithObject:runner]];  
}

父母的委托代码是:

- (void)runnerAddViewController:(RunnerAddNewViewController *)runnerAddViewController 
                  didAddRunners:(NSArray *)runners {
    if (runners) {
           //stuff interacting with my model
    }
    // Dismiss the modal addRunner view controller
    [self dismissModalViewControllerAnimated:YES];
}

有关实验的任何线索或建议或在哪里观看?是否从正确的位置调用dismissModalVC(以解除两个级别)?

2 个答案:

答案 0 :(得分:2)

原来这是一个真正的错误。如果您在用户单击搜索中的某个人时对双重ModalVC解除ABPeoplePicker,则会导致此崩溃。幸运的是,有一个简单的解决方法:在委托中输入YESContinueAfterSelectingPerson。当你同时解雇选择器时,无论你返回YES还是NO都没关系,它不会继续,但NO会崩溃而YES不会崩溃。

答案 1 :(得分:-1)

使用NSZombieEnabled运行,我怀疑你将用一个在释放后访问某个对象的错误替换断言失败。