【问题标题】:Weird crash in ABPeoplePickerABPeoplePicker 发生奇怪的崩溃
【发布时间】:2011-02-18 08:53:17
【问题描述】:

我正在使用 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: 方法 调用一个人的适当信息。委托本身是一个模态控制器,因此它保存信息并回调其父级,后者调用 [selfdismissModalViewControllerAnimated: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: interrupted。对这意味着什么有任何想法?

委托的代码是:

- (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(解除两个级别)?

【问题讨论】:

  • 您没有从 peoplePickerNavigationController:shouldContinueAfterSelectingPerson 返回 BOOL 是否有原因?
  • 不,它不是,但它只是在试图缩短它时被删除了。请参阅stackoverflow.com/questions/4856728 以获得相同问题的更简洁版本。现在与 Apple 合作;会回来报告的。

标签: iphone objective-c cocoa-touch abpeoplepickerview


【解决方案1】:

原来这是一个实际的错误。如果您在用户单击搜索中的人时对 ABPeoplePicker 执行双重 ModalVC 关闭,您将遇到此崩溃。幸运的是,有一个简单的解决方法:在您的委托的 shouldContinueAfterSelectingPerson 中返回 YES。当您同时关闭选择器时,返回 YES 或 NO 并不重要,它不会继续,但 NO 会崩溃而 YES 不会。

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 很遗憾没有。之前有一点,我通常在启用的情况下运行(根据你的建议,我尝试了几个测试以确保 NSZombieEnabled 正常运行)。还有其他建议吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-16
    • 2019-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多