UITableViewController with Section and Parse as BackEnd Server

I didn't find any good and updated answers about loading data from Parse into a UITableViewController with sections.

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

I have a Recipes class 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 am calculating a function to request data from Parse as follows:

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

From here I am a bit lost on how to proceed to achieve the desired results.

Please, help,

Thank you in advance

+3


source to share


1 answer


You need to create different sections based on the Section property for each returned object. This is a little tricky for someone new to UITableView

, but can be done in about an hour using Sensible TableViews ( http://sensiblecocoa.com/ ).

The sane TableViews will allow you to take an array of objects and split it into multiple sections. It even interacts directly with Parse.com if you so desire. I use it in almost all of my applications for its simple, clean approach to tables and cloud data.



Get started with your online tutorial here: http://sensiblecocoa.com/usermanual/latest/

You can also go to Parse.com integration here: http://sensiblecocoa.com/usermanual/latest/#ExploringParseComBinding

+2


source







All Articles