在PFQueryTableViewController中按object.count排序

时间:2015-06-19 08:11:28

标签: swift parse-platform

我需要查询类中的所有对象,并按Swift中每个对象的频率对它们进行排序。我正在使用...

获取查询
// Define the query that will provide the data for the table view
    override func queryForTable() -> PFQuery{
        var query = PFQuery(className: "Upvotes")
        return query
    }

...但似乎无法检索objects.count项目,因为我无法使用带有findObjectsInBackground调用的异步完成块。这是我应该在cellForRowAtIndexPath()

中处理的事情

1 个答案:

答案 0 :(得分:0)

但你可以这样做:

class demo: UIViewController {

    var parseObjects: NSArray!

    override func viewDidLoad() {
    }

    // Define the query that will provide the data for the table view

    func yourQuery() -> PFQuery {
        var query = PFQuery(className: "Upvotes")

        query.findObjectsInBackgroundWithBlock {
            (objects: [AnyObject]?, error: NSError?) -> Void in

            if error == nil {
                if (objects!.count > 0) {
                    parseObjects = objects //Store those objects in your variable
                }

            } else {
                // Log details of the failure
                println("Error: \(error) \(error!.userInfo!)")
            }
        }
    }
}

之后在tableViewDelegate中使用parseObjects变量...