xcode swift cell detailTextLabel.text ?.从日期
我尝试改变labelcolor采取的颜色,如果在我的detailTextLabel.text“约会”前辈那么今天..xcode swift cell detailTextLabel.text ?.从日期
// Configure the cell...
cell.textLabel?.textColor = UIColor.blueColor()
cell.detailTextLabel?.textColor = UIColor.darkGrayColor()
let item = frc.objectAtIndexPath(indexPath) as! Item
cell.textLabel?.text = item.name! + "-" + item.etage! + "-" + item.raum!
let note = item.date
cell.detailTextLabel!.text = "\(note!)"
if note == "01.04.2016 23:00" {
cell.detailTextLabel?.textColor = UIColor.redColor()
} else {
}
return cell
}
我怎样才能做到这一点?它适用于特定的日期,但不适用于NSDate()或类似的东西。我疯了!
大thx!
正如指出there可以让这样的事情:
...
let note = item.date
let now = NSDate()
if note.earlierDate(now).isEqualToDate(note) {
cell.detailTextLabel?.textColor = UIColor.redColor()
}
thx =)但现在我有一条消息:类型'String?'的值has no member'earlierDate' – slevin
在代码中使用[this](http://*.com/a/29319732/3466461)扩展 – giacavicchioli
应该验证答案是否有效。 – giacavicchioli
检查这个http://*.com/questions/26807416/check-if-date-is-before-current-date-swift和请确保与相同的格式 –
比较显然你的Item.date是字符串格式,所以不可能直接与NSDate对象进行比较。 – sleepwalkerfx