Jojo
Jojo

Reputation: 459

UITableViewController with Section and Parse as BackEnd server

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

Upvotes: 3

Views: 84

Answers (1)

Ryan Kreager
Ryan Kreager

Reputation: 3581

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

Upvotes: 2

Related Questions