gpt4 book ai didi

swift - 在 PFQueryTableViewController 中按 object.count 排序

转载 作者:行者123 更新时间:2023-11-30 14:17:37 26 4
gpt4 key购买 nike

我需要查询一个类中的所有对象,并按照每个对象在 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 项,因为我无法将异步完成 block 与 findObjectsInBackground 调用一起使用。这是我应该在 cellForRowAtIndexPath() 中处理的事情吗?

最佳答案

但是你可以这样做:

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 变量...

关于swift - 在 PFQueryTableViewController 中按 object.count 排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30933175/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com