我正在从Firebase检索包含日期的数据。我只想显示日期已经过去的项目。目前显示日期是否已经过了日期,例如,如果日期是25/02/17,那么26日及之后的日期将不显示,但是日期低于25日将尽管月份是什么。那么如何才能让它考虑到月份和年份呢?
以下是我目前的代码。
func setupAgendaData() {
var ref: FIRDatabaseReference!
ref = FIRDatabase.database().reference()
let userID = FIRAuth.auth()?.currentUser?.uid
print(userID)
ref.child("users").child(userID!).child("Agenda").observeEventType(.Value, withBlock: { (snapshot) in
self.agenda.removeAll()
print(snapshot)
for item in snapshot.children.allObjects as! [FIRDataSnapshot] {
if let dictionary = item.value as? [String: AnyObject] {
let agendaItem = Agenda()
agendaItem.setValuesForKeysWithDictionary(dictionary)
self.agenda.append(agendaItem)
}
}
dispatch_async(dispatch_get_main_queue(), {
self.collectionView.reloadData()
})
}) { (error) in
print(error.localizedDescription)
}
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
/* let actDate = ActDate()
let date = NSDate()
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd/MM/yy"
actDate.date = dateFormatter.stringFromDate(date)
//if self.agenda < actDate.date {
print(agenda.count)
// }
print(agenda.count)
*/
return agenda.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let previousCell = collectionView.dequeueReusableCellWithReuseIdentifier(previousCellId, forIndexPath: indexPath) as! PreviousCell
let actDate = ActDate()
let date = NSDate()
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd/MM/yy"
actDate.date = dateFormatter.stringFromDate(date)
let filtAgenda = agenda[indexPath.item].date < actDate.date
if filtAgenda == true {
previousCell.nameLabel.text = agenda[indexPath.item].activity
previousCell.timeLabel.text = agenda[indexPath.item].time
previousCell.dateLabel.text = agenda[indexPath.item].date
}
return previousCell
}