0

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. 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:

"*** -[__NSArrayM objectAtIndex:]: index 10 beyond bounds [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.

Any guidance will be greatly appreciated!

DevKyle
  • 1,091
  • 6
  • 22

1 Answers1

0

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.

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

    }
}
DevKyle
  • 1,091
  • 6
  • 22