如何让tableview单元格从下到上填充?

时间:2017-05-07 18:50:10

标签: ios arrays swift uitableview firebase

我想在桌面视图中让单元格从底部开始。它目前正在从上到下。我正在从firebase中检索数据。我该怎么做呢(反过来)。谢谢!

var posts = [postStruct]()



override func viewDidLoad() {
    super.viewDidLoad()


    let ref = FIRDatabase.database().reference().child("Posts")

    ref.observeSingleEvent(of: .value, with: { snapshot in

        print(snapshot.childrenCount)

        for rest in snapshot.children.allObjects as! [FIRDataSnapshot] {

            guard let value = rest.value as? Dictionary<String,Any> else { continue }

            guard let  title = value["Title"] as? String else { continue }

            let post = postStruct(title: title)

            self.posts.append(post)

        }

        self.tableView.reloadData()
    })
}




override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return posts.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell")

    let label1 = cell?.viewWithTag(1) as! UILabel
    label1.text = posts[indexPath.row].title
    return cell!
}

}

1 个答案:

答案 0 :(得分:1)

试试这个:

self.posts.reversed().forEach {
    print($0)
}