2015-06-05 34 views
0

我正在處理我的應用程序的iPad版本,並且遇到了一個奇怪的問題。iPad SearchViewController崩潰_PFArray objectAtIndex超出界限

這裏的應用程序的結構:

UISplitViewController
- > MasterViewController
- > NavigationController
---> TableViewController
----> PrototypeCells
---> SearchDisplayController
- > DetailViewController
- > NavigationController
---> TableViewControlle ř
----> StaticCells

基本上,應用程序被顯示像40個000行與CoreData和fetchResultController上馬西德威。用戶可以使用searchDisplayController搜索項目或使用新的FetchResultController對TableView進行排序。當單擊一行時,didSelectRowAtIndexPath方法在detailView中設置Item。

的問題是,有時當我點擊搜索欄,應用程序崩潰與此錯誤消息:

**Terminating app due to uncaught exception 'NSRangeException', 
reason: ' -[_PFArray objectAtIndex:]: index (11) beyond bounds (X)'** 

但我想我找到了一個場景,使應用程序崩潰everytimes:

  1. 應用負載
  2. 我搜索具有5個或6個字母搜索字符串所以 項由searchViewController返回的量是相當小的(如5 項)。我認爲「越界(X)」對應於這個數量的項目。
  3. 我取消搜索
  4. 我的的tableView一個新的FetchResultController
  5. 我的搜索欄,用途類型排序立即崩潰

如果我做同樣的場景,但與2一個搜索或3個字母,以便searchViewController返回的項目數量更大,沒有崩潰。

此外,應用此場景時,iPhone版本沒有問題/崩潰。

我不明白問題在哪裏,它讓我發瘋。有人想知道哪裏出了問題嗎?我可以更新這篇文章來添加代碼,但現在,我不知道哪個部分是有用的瞭解崩潰。

感謝您的閱讀。

回答

0

所以我想我找到了一個解決方案。

在我TableViewController斷點播放後,我發現,這是在搜索欄錄音時墜毀的方法是的cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    ItemCell *cell = [self.tableView dequeueReusableCellWithIdentifier:ItemCellIdentifier forIndexPath:indexPath]; 
    Item *item = nil; 
    if (self.searchDisplayController.active) { 
     item = [self.filteredList objectAtIndex:indexPath.row]; 
    } else { 
     item = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    } 
    //... 
    return cell; 
} 

特別是這一行:項= [self.filteredList objectAtIndex:indexPath 。行];

我試圖清空filteredList當用戶停止使用這種方法搜索並沒有更多的崩潰:

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller { 
    self.filteredList=nil; 
} 
相關問題