简体   繁体   English

轻按“加载更多”时(分页),PFQueryTableViewController崩溃

[英]PFQueryTableViewController crashes when “Load More” is tapped (pagination)

I've looked at similar questions and tried different solutions to no avail. 我看过类似的问题,并尝试了不同的解决方案,但无济于事。 I've implemented PFQueryTableViewController in my iOS app, and I've followed Parse iOS documents. 我已经在iOS应用中实现了PFQueryTableViewController,并且遵循了Parse iOS文档。 Everything works well, except when I tap on "Load More" to get the next x number of Parse objects, the app crashes with the following message: 一切正常,除非当我点击“加载更多”以获取下一个x个Parse对象时,应用程序崩溃并显示以下消息:

"*** -[__NSArrayM objectAtIndex:]: index 10 beyond bounds [0 .. 9]" “ ***-[__ NSArrayM objectAtIndex:]:索引10超出范围[0 .. 9]

I know what the message means, but since I am using the PFQueryTableViewController instead of the usual UITableViewController, I am not sure how I can troubleshoot this range problem. 我知道消息的含义,但是由于我使用的是PFQueryTableViewController而不是通常的UITableViewController,所以我不确定如何解决此范围问题。

Any guidance will be greatly appreciated! 任何指导将不胜感激!

So for those of you who are interested, the reason why the pagination crashed is because I've implemented the following method, which the example on Parse document didn't. 因此,对于那些感兴趣的人来说,分页崩溃的原因是因为我实现了以下方法,而Parse文档中的示例没有这样做。

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

So in order for you to reload data without crashing, following code needs to be implemented: 因此,为了使您重新加载数据而不会崩溃,需要实现以下代码:

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()

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM