【发布时间】:2016-01-07 16:36:04
【问题描述】:
每个单元格都包含日期和信息(文本)。默认情况下,排序是相反的。它按时间的相反顺序排序。我想更改当前日期之前单元格中单元格的背景颜色。
tableView cellForRowAtIndexPath :
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexpath) as! tableViewCell
cell.dateLabel.text = stores.date
cell.contentLabel.text = stores.content
let today = NSDate()
if today == (stores.date) {
cell.backgroundColor = UIColor.blueColor()
} else {
cell.backgroundColor = UIColor.clearColor()
}
return cell
【问题讨论】:
-
你有什么问题?
-
如果日期相等比较有问题,试试
isEqualToDate方法 -
你需要的是 NSCalendar 方法 isDateInToday developer.apple.com/library/mac/documentation/Cocoa/Reference/…:
-
你可能也对这个感兴趣stackoverflow.com/a/34457607/2303865
标签: ios swift nsdate tableviewcell