我正尝试按日期升序在Tableview中显示Firebase数据。我还尝试实现两个按钮“过去”和“即将到来”,以再次过滤数据。 “过去”按钮应显示当前日期之前的所有数据。 “即将到来”按钮应显示具有当前日期和将来日期的所有数据。这是我目前正在接收数据的方式...
Firebase json数据结构如下-
这是我的代码-
refReleases = Database.database().reference().child("releases");
refReleases.observe(DataEventType.value) { (snapshot) in
if snapshot.childrenCount>0{
self.releasesData.removeAll()
for releases in snapshot.children.allObjects as![DataSnapshot]{
let releaseObject = releases.value as? [String: AnyObject]
let releaseName = releaseObject?["releaseName"]
let releaseType = releaseObject?["releaseType"]
let releasePrice = releaseObject?["releasePrice"]
let releaseDate = releaseObject?["releaseDate"]
let releaseImage = releaseObject?["releaseImage"]
let releaseTag = releaseObject?["releaseTag"]
let nikewebsite = releaseObject?["nikewebsite"]
let finishlinewebsite = releaseObject?["finishlinewebsite"]
let eastbaywebsite = releaseObject?["eastbaywebsite"]
let footlockerwebsite = releaseObject?["footlockerwebsite"]
let footactionwebsite = releaseObject?["footactionwebsite"]
let champswebsite = releaseObject?["champswebsite"]
let release = ReleaseModel(releasetype: releaseType as! String?, releasename: releaseName as! String?, releaseprice: releasePrice as! String?, releasedate: releaseDate as! String?, releaseimage: releaseImage as! String?, releasetag: releaseTag as! String?, nikewebsite: nikewebsite as! String?, finishlinewebsite: finishlinewebsite as! String?, eastbaywebsite: eastbaywebsite as! String?, footlockerwebsite: footlockerwebsite as! String?, footactionwebsite: footactionwebsite as! String?, champswebsite: champswebsite as! String?)
self.releasesData.append(release)
}
self.tableView.reloadData()
}
@IBAction func pastButtonTapped(_ sender: UIButton) {
//show data before the current date
}
@IBAction func upcomingButtonTapped(_ sender: UIButton) {
//show data of current and future dates
}