我正在使用 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:在我输入搜索框时被中断。关于这意味着什么的任何想法?
委托人的代码是:
- (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(解除两个级别)?