2017-02-09 46 views
0

我已經看過類似的問題,並試過不同的解決方案無濟於事。我在我的iOS應用程序中實現了PFQueryTableViewController,並且遵循了Parse iOS文檔。一切運作良好,除非當我點擊「加載更多」來獲得下一個x數量的Parse對象時,應用程序崩潰,並顯示以下消息:PFQueryTableViewController在「加載更多」時會崩潰(分頁)

「*** - [__ NSArrayM objectAtIndex:]:index 10 beyond bounds [0..9]「

我知道該消息的含義,但由於我使用的是PFQueryTableViewController而不是通常的UITableViewController,我不知道如何解決這個範圍問題。

任何指導將不勝感激!

回答

0

因此,對於那些感興趣的人來說,分頁崩潰的原因是因爲我實現了以下方法,而Parse文檔中的例子並沒有這樣做。

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 

因此,爲了使您重新加載數據沒有崩潰,下面的代碼需要實現:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

    if indexPath.row <= (self.objects!.count - 1) { 

     //These are the cells populated by your PFQuery objects 
     //Do whatever you want to do with the selected cell 

    } else { 

     //This is if the "Load More" cell is selected 

     self.loadNextPage() 

    } 
}