PFQueryTableViewController在“加载更多”时会崩溃(分页)
问题描述:
我已经看过类似的问题,并试过不同的解决方案无济于事。我在我的iOS应用程序中实现了PFQueryTableViewController,并且遵循了Parse iOS文档。一切运作良好,除非当我点击“加载更多”来获得下一个x数量的Parse对象时,应用程序崩溃,并显示以下消息:PFQueryTableViewController在“加载更多”时会崩溃(分页)
“*** - [__ NSArrayM objectAtIndex:]:index 10 beyond bounds [0..9]“
我知道该消息的含义,但由于我使用的是PFQueryTableViewController而不是通常的UITableViewController,我不知道如何解决这个范围问题。
任何指导将不胜感激!
答
因此,对于那些感兴趣的人来说,分页崩溃的原因是因为我实现了以下方法,而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()
}
}