1

What is the best way to get data from Parse in a TableView, be able to create different sections and only store the 30 newest objects locally?

My Applikation has an PFObject Challenge, the Challenge can be in the state "Accepted" or "Not Accepted". These are also my two Sections in the TableView. When Accepting a Challenge, it should "Pop" down to the Accepted Challenge Section. This is done with a Boolean.

I would like to use PFQueryTableViewController if its possible since it implements some useful features, but i found out that it only supports TableViews with 1 section by default. Right now im considering to load the 30 newest PFObject of the Challenge class and sort them into a Dictionary with 2 Arrays "Accepted" and "Not Accepted", using a standard UITableViewController. The loading would be done in the "ViewDidLoad" Method. Is this the right way doing this?

Also i would like to use the pin feature of Parse and save the Data locally, so the User can still use the App when there is no internet connection. How do i implement that only the 30 newest objects are saved?

Daniel Storch
  • 979
  • 3
  • 10
  • 25

1 Answers1

0

You are correct in going with a UITableViewController, since indeed PFQueryTableViewControllers are indeed mainly for 1 section tables. What you should do is set up the queries for your tables in viewDidLoad:, and have a call back that refreshes the table when those results are fetched.

As far as actual implementation, you haven't mentioned whether you are working in Swift or Objective-C, so I'd just refer you to the parse documentation for queries for either case without knowing which one you need: https://www.parse.com/docs/ios_guide#queries/iOS

Edit: Based on your comment, sorry I didn't see the Swift in title. In Swift, you can set the query parameters such that the items are ALREADY sorted by parse on the backend, and also limit the query return to 30 elements. To do so, it's simply these two lines:

query.limit = 30
query.orderByAscending("timeCreated")
BHendricks
  • 4,423
  • 6
  • 32
  • 59
  • Im working with Swift (wrote it in the Title). After i got the call back and i have downloaded all data, i still need to sort them into an dictionary for my TableView? And how do i make sure that only the 30 newest Objects are saved locally with the "pin" feature? – Daniel Storch Apr 27 '15 at 15:40
  • I'm not too sure about the pin, but u can definitely set the amount of results to get by sorting by creation time and getting 30 results. – BHendricks Apr 27 '15 at 16:02