Ios 以降序显示解析中的最后30条记录

Ios 以降序显示解析中的最后30条记录,ios,swift,uitableview,parse-platform,Ios,Swift,Uitableview,Parse Platform,我想通过按“创建”日期排序,从UITableView中的Parse加载最后30条记录(本例中为消息)。我可以做到这一点,但是,消息在第30条记录之前都会被排序,接下来的记录不会显示在我的UITableView中 这是我的密码: let messagesQuery = PFQuery(className: "Message") messagesQuery.includeKey("conversation") messagesQuery.includeKey("author") messagesQu

我想通过按“创建”日期排序,从UITableView中的Parse加载最后30条记录(本例中为消息)。我可以做到这一点,但是,消息在第30条记录之前都会被排序,接下来的记录不会显示在我的UITableView中

这是我的密码:

let messagesQuery = PFQuery(className: "Message")
messagesQuery.includeKey("conversation")
messagesQuery.includeKey("author")
messagesQuery.whereKey("conversation", equalTo: conversation)
messagesQuery.orderByAscending("createdAt")
messagesQuery.limit = 30
messagesQuery.findObjectsInBackgroundWithBlock { (results, error) -> Void in
}
我知道我可以使用降序(“createdAt”)来代替。。。但是,如果我这样做,我的消息的顺序是相反的。我的意思是,我收到了最后30条消息,但顺序颠倒了(最早的消息出现在对话的底部,最近的消息出现在顶部)

那么,我如何才能修复它,使其显示最后30条消息,而最新的消息则显示在我对话的底部


谢谢

为查询设置跳过值

[messagesQuery setSkip: 0];
参考链接

尝试orderByAscending(“创建数据”)


当用户向下滚动到前30条消息的底部时,听起来您希望有一个加载更多按钮。您可以使用“加载更多”按钮,也可以在用户到达底部时自动加载。

您可以尝试在结果块中对它们进行如下排序:

let messagesQuery = PFQuery(className: "Messages")
    messagesQuery.includeKey("conversation")
    messagesQuery.includeKey("author")
    messagesQuery.whereKey("conversation", equalTo: conversation)
    messagesQuery.orderByDescending("createdAt")
    messagesQuery.limit = 30
    messagesQuery.findObjectsInBackgroundWithBlock { (results, error) -> Void in
        if var messages: Array<PFObject> = results {
            for message in messages {
                print(message.createdAt!)
            }
            messages.sortInPlace({ $0.createdAt!.compare($1.createdAt!) == NSComparisonResult.OrderedAscending })
            print("")
            for message in messages {
                print(message.createdAt!)
            }
        }
    }
let messagesQuery=PFQuery(类名:“Messages”)
messagesQuery.includeKey(“对话”)
messagesQuery.includeKey(“作者”)
messagesQuery.whereKey(“对话”,等同于:对话)
messagesQuery.orderByDescending(“createdAt”)
messagesQuery.limit=30
messagesQuery.FindObjectsInBackgroundithBlock{(结果,错误)->中的Void
如果var消息:Array=results{
对于消息中的消息{
打印(message.createdAt!)
}
messages.sortInPlace({$0.createdAt!.compare($1.createdAt!)==NSComparisonResult.OrderedAscending})
打印(“”)
对于消息中的消息{
打印(message.createdAt!)
}
}
}