In my app I can add an event and they event will show up in a tableView as cell with the information of the event. Now I want to be able to set the date of the event and then the cell will only add to the tableView if that date is before the current date (the event happened in the past). Heres the code:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let e = events[indexPath.row]
let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomCell
let Date1 = e.eventDate
let Date2 = NSDate()
if Date1!.earlierDate(Date2).isEqualToDate(Date1!) {
// Sets labels in cell to whatever user typed in on the events page
cell.titlePrototypeCell!.text = e.eventTitle!
} else {
//Code to not add a cell
}
return cell
}
The problem with this is that if the event date is after the current date (in the future) then a regular cell is added to the tableView instead of no cell at all. Any ideas on how to not add a cell if the event is in the future?