self.messageFromId.removeAll()
self.messageFrom.removeAll()
self.taskTitle.removeAll()
self.message.removeAll()
self.taskId.removeAll()
self.messageId.removeAll()
self.messageType.removeAll()
if PFUser.current()?.objectId! != nil {
let query = PFQuery(className: "Message")
query.addDescendingOrder("createdAt")
query.limit = 10
cur = PFUser.current()!.objectId!
query.whereKey("messageTo", equalTo: cur!)
query.findObjectsInBackground(block: { (objects, error) in
if let posts = objects{
for object in posts {
if let post = object as? PFObject {
let query2 = PFUser.query()
query2?.whereKey("objectId", equalTo: post["messageFrom"] as! String)
query2?.findObjectsInBackground(block: { (objects, error) in
if let posts = objects{
for object in posts {
if let post2 = object as? PFObject {
if post2["handle"] as! String == "new$!" {
self.messageFromId.append(post["messageFrom"] as! String)
self.messageFrom.append(post["messageFrom"] as! String)
self.taskTitle.append(post["taskTitle"] as! String)
self.message.append(post["message"] as! String)
self.taskId.append(post["taskId"] as! String)
self.messageId.append(post.objectId!)
self.messageType.append(post["messageType"] as! String)
} else {
self.messageFromId.append(post["messageFrom"] as! String)
self.messageFrom.append(post2["handle"] as! String)
self.taskTitle.append(post["taskTitle"] as! String)
self.message.append(post["message"] as! String)
self.taskId.append(post["taskId"] as! String)
self.messageId.append(post.objectId!)
self.messageType.append(post["messageType"] as! String)
}
}
}
}
self.tableView.reloadData()
self.refresher.endRefreshing()
})
}
}
}
})
}
结果似乎以随机顺序回归,不知道为什么?我是否正确地在查询中进行查询?
我在查询开头添加了:query.addDescendingOrder(“createdAt”)。它无法正常工作
答案 0 :(得分:0)
请尝试使用:query.order(byDescending: "createdAt")
。