I'm using PFQueryTableViewController
in my project, and I just discovered a pretty annoying problem.
I'm using the pagination, everything works fine, but when the current user just finished loading/refreshing for the table(not loading for next page), suddenly another user makes a post(let's call it object0), then the pagination won't work as expected. For example, I have 100 objects on the Parse server, and the objectsPerPage
is set to 10. And this is what the table looks like after current user loading the table:
object1
object2
object3
...
object10
load next page
Then suddenly another user makes a post "object0", and when the current user finishes loading next page, the table looks like this:
object1
object2
...
object10
object10
object11
...
object 19
load next page
which gives me two "object10". And this is perfect reasonable because this is what Parse's logic for loadNextPage
:
query.limit = self.objectsPerPage; //retrieve 10 objects per query
query.skip = page * self.objectsPerPage; //skip 10*current_page objects per query
As you can see, when another user makes a post(let's call it "object0"), there will be 101 objects on the server, but the table are still displaying from "object1" to "object10" coz it's not refreshed. And when current user is loading the 2nd page(this is not refreshing), the server's gonna skip the first 10 objects("object0" to "object 9", rather than 1 to 10), therefore the result for second page will be "object 10" to "object 19", thus, there will be two "object 10" in the table.
Is there a way to eliminate this issue?
And sorry for my poor english, if you are not sure what I meant to say, just comment below and I will explain further.
Many thanks.
I managed to solve it myself. Here is the approach:
lastObject
, which is the last object that the query returns.lastObject
.self.parseClassName
, and then enumerate through the result, if the objectId of the lastObject
is equal to an objectId in the result, then set the query.skip = (index + 1)*page
. where index
is the index of the object in the result array which matches the lastObject
.loadNextPage
, the query should return the next 10 objects right after the lastObject
.It's a bit tricky, if anyone is facing the same problem, feel free to drop a message and I will expain my approach in detail. :)