2011-01-27 148 views
0

我使用ABPeoplePicker和我得到一個奇怪的崩潰:用戶使用搜索字段,然後挑選一個候選人產生後奇怪的崩潰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是否從正確的位置被調用(解散兩個級別)?

+0

是否有一個原因,你沒有從peoplePickerNavigationController返回BOOL:shouldContinueAfterSelectingPerson? – 2011-02-17 18:40:03

+0

不是,它不是,但它試圖縮短它只是被刪除。請參閱http://stackoverflow.com/questions/4856728/,以獲取更清晰的相同問題。現在與蘋果合作;將回報。 – mackworth 2011-02-17 22:11:53

回答

2

原來這是一個實際的錯誤。如果您在用戶單擊搜索中的某個人時對ABPeoplePicker執行了雙ModalVC解僱,則會導致此次崩潰。幸運的是,有一個簡單的解決方法:在委託的shouldContinueAfterSelectingPerson中返回YES。由於您同時拒絕選擇器,所以返回YES或NO並不重要,它不會繼續,但NO會崩潰,YES不會。

-1

使用NSZombieEnabled運行,我懷疑你會用一個對象在被釋放後被訪問的錯誤來替換斷言失敗。