3

I don't find any good and update answers about loading data from Parse to an UITableViewController with sections.

I know that using PFQueryTableViewController is only possible for 1 section.

I have a class Recipes with the following columns in Parse: Section; Name; Calories

Hence my database looks like this Morning; Eggs; 120 Morning, Bacon; 250 Lunch; Meat; 340 ....

I compute a function to query the data from Parse like this:

func queryData(){
    var query = PFQuery(className: self.recipesClass as String)
    //query.cachePolicy = .CacheElseNetwork
    query.orderByDescending("createdAt")

    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in
        if error == nil {
            // Results were successfully found, looking first on the
            // network and then on disk.
            // Do something with the found objects
            if let objects = objects as? [PFObject] {
                for object in objects {
                    self.tableSections.addObject(object)
            }

        } else {
            // The network was inaccessible and we have no cached data for
            // this query.
        }
    }
}

Where tableSections is a NSMutableArray.

From here, I'm a bit lost on how to proceed to achieve the required results.

Please help,

Thank you in advance

2
  • Would you like the sections on the UITableView to match the sections on the Parse.com table? Also, how familiar are you with UITableView? Commented May 11, 2015 at 19:18
  • Yes! The section's names from Parse.com must match with the sections of UITableView. I'm a beginner but I have the basics on UITableView concept Commented May 11, 2015 at 19:38

1 Answer 1

2

You will want to create different sections based on the 'Section' property of each returned object. This is a bit tricky for someone new to UITableView, but it can be accomplished in around an hour with Sensible TableViews (http://sensiblecocoa.com/).

Sensible TableViews will let you take an array of objects and separate it into several sections. It even interfaces directly with Parse.com if you so desire. I use it in almost all of my apps for its simple, clean approach to tables and cloud data.

Start with their online guide here: http://sensiblecocoa.com/usermanual/latest/

You can also skip right to Parse.com Integration here: http://sensiblecocoa.com/usermanual/latest/#ExploringParseComBinding

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you. I will investigate this but in a first lecture it doesn't treat the multiple section aspect. Is there another way than using Sensitive TableViews ? It doesn't seems to be free to use Parse.com Binding. Thank you for your help
Maybe it should be better to create a class Recipes : PFObject, PFSubclassing and define attributes inside no ?
Agreed- I would use the PFObject subclassing as opposed to key-value coding via objectForKey: calls.
I didn't achieve it yet :( For now I have an array of dictionnaries where each cell of this array is a PFObject transform to a NSMutableDictionnary (Section, Name, Calories) I don't know how to display it by section. Any ideas guys ? Please
Did you end up using sensible cocoa or the native UITableView delegates? Open a new question and I'll help you solve the sections separation issue :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.