2016-04-08 10 views
0
i labelcolor değiştirmeye çalışan

alınan eğer eski benim detailTextLabel.text içinde "tarih" o zaman bugün .. xcode hızlı hücre detayıTextLabel.text ?. renk, tarih

 // 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 
} 

Bu nasıl yapabilirim? Belirli bir tarihle çalışır, ancak NSDate() ile veya bunun gibi bir şeyle değil. Çıldırıyorum!

big thx!

+0

onay bu http://stackoverflow.com/questions/26807416/check-if-date-is-before-current-date-swift ve Aynı formatta –

+0

ile karşılaştırdığınızdan emin olun Item.date öğeniz Dize biçiminde olduğundan, doğrudan bir NSDate nesnesiyle karşılaştırmak mümkün değildir. – sleepwalkerfx

cevap

0

olarak böyle bir şey yapabilir there çekti:

... 
let note = item.date 
let now = NSDate() 

if note.earlierDate(now).isEqualToDate(note) { 
    cell.detailTextLabel?.textColor = UIColor.redColor() 
} 
+0

thx =) ancak şimdi bir mesajım var: "String?" Türünün değeri 'firstDate' kullanıcısı yok – slevin

+0

Kodunuzda [this] (http://stackoverflow.com/a/29319732/3466461) uzantısını kullanmaya çalışın – giacavicchioli

+0

Çalışırsa yanıt doğrulanmalıdır. – giacavicchioli

İlgili konular