从Firebase数据库中检索的UITableView of Childs中的反向显示顺序

时间:2016-08-13 11:03:15

标签: swift uitableview firebase firebase-realtime-database

目前我的数据库如下所示:

<posts>
 - "1"
 - "2"
 - "3"

这也是我使用以下方式检索和订购此数据到我的iOS应用程序的顺序:

func getQuery() -> FIRDatabaseQuery {
    let myTopPostsQuery = (ref.child("posts"))

    return myTopPostsQuery
}

override func viewDidLoad() {
    super.viewDidLoad()


    self.ref = FIRDatabase.database().reference()

    dataSource = FirebaseTableViewDataSource.init(query: getQuery(),prototypeReuseIdentifier: "Cellident", view: self.tableView)


    dataSource?.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in

        let customCell = cell as! CustomCellTableViewCell
        let snap = obj as! FIRDataSnapshot
        let childString = snap.value as! [String : AnyObject]

        customCell.textLabel.text = String(childString)}

    } 

   tableView.dataSource = dataSource
   tableView.delegate = self

}

然后显然它以相同的顺序从1到3显示在表格中。我想要实现的是以相反的顺序显示它,以便首先显示数据库中的最后一个元素,即3,2,然后是表中最后一个(最下面的)元素。

Haven在文档中找不到任何关于此事的内容,主要是关于按价值排序。我猜我要么让firebase以不同的顺序检索它,要么填充表格单元格反转?

0 个答案:

没有答案