tableViewCellに "lblProjeDurumu"というラベルがあります。 soap webServicesからこのラベルにデータを取得します。データは「Devam Ediyor」または「Başlamadı」です。 着信データが "Devam Ediyor"、lblProjeDurumuのtextColorが緑色、着信データが "Başlamadı"の場合、lblProjeDurumuのtextColorが赤色になります。私のコードはここにあります。SwiftのtableViewCellでラベルのテキストの色を変更する方法は?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "projelerCell", for: indexPath) as! ProjelerCell
cell.contentView.backgroundColor = UIColor(white: 0.95, alpha: 1)
// Fill the projeler cell
cell.lblProjeAdi.text = (projeler.object(at: indexPath.row) as AnyObject).value(forKey: "Proje_Adi") as? String
cell.lblProjeDurumu.text = (projeler.object(at: indexPath.row) as AnyObject).value(forKey: "Durumu") as? String
cell.lblTarih.text = (projeler.object(at: indexPath.row) as AnyObject).value(forKey: "Kayit_Tarihi") as? String
if (cell.lblProjeDurumu.text == "Başlamadı"){
cell.lblProjeDurumu.textColor = UIColor.red
}
else if (cell.lblProjeDurumu.text == "Devam Ediyor"){
cell.lblProjeDurumu.textColor = UIColor.green
}
return cell
}
しかし変更はありません。 lblProjeDurumuのtextColorはまだデフォルトの色です。着信データに応じてtableViewCellのLabelのtextColorを変更する方法
「if」ブロックと「else if」ブロックにブレークポイントを追加しようとしましたか?たぶん、文字列に空白があります。この場合、比較は失敗します。 – dasdom
あなたの答えをありがとう。私は問題を解決する。あなたが言ったように、文字列にはスペースがあります。私は "Başlamadı"を "Başlamadı"と "Devam Ediyor"を "Devam Ediyor"に変更したので、問題は修正されました。 –