カスタムテーブルビューのセルに設定されている画像ビューで画像を読み込む際に問題があります。すべての画像ビューが同じ画像で設定されていますが、コード内の私の要件に応じて画像。これは私がイメージをロードするために実装したコードです。カスタムTableViewセルに画像を読み込むことができません
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "AfricaCell", for: indexPath) as! AfricaCell
var curpricefloat : Double = Double(CurrPrice[indexPath.row])!
curpricefloat = Double(round(100*curpricefloat)/100)
var Chgfloat : Double = Double(Chg[indexPath.row])!
Chgfloat = Double(round(100*Chgfloat)/100)
var perchgfloat : Double = Double(PerChg[indexPath.row])!
perchgfloat = Double(round(100*perchgfloat)/100)
cell.Indicename?.text = Indicename[indexPath.row]
cell.Country?.text = CountryArray[indexPath.row]
cell.PerChg?.text = "(" + String(perchgfloat) + "%)"
cell.CurrPrice?.text = String(curpricefloat)
cell.Chg?.text = String(Chgfloat)
if Float((cell.Chg?.text)!)! < 0 {
Chgfloat = abs(Chgfloat)
perchgfloat = abs(perchgfloat)
cell.PerChg?.text = "(" + String(perchgfloat) + "%)"
cell.Chg?.text = String(Chgfloat)
cell.Chg?.textColor = UIColor.red
cell.PerChg?.textColor = UIColor.red
cell.arrow?.image = UIImage(named : "arrowdown")
} else
{
cell.Chg?.textColor = UIColor.green
cell.PerChg?.textColor = UIColor.green
cell.arrow?.image = UIImage(named : "arrowup")
}
/* This is the code which i have written for loading the images ,
but all the cells are being loaded with the image named : "unknown"
except the last cell which are having the name of country as "South Africa" */
if cell.Country!.text! == "Egypt"{
cell.countryFlag?.image = UIImage(named : "egypt")
}
if cell.Country!.text! == "Kenya"{
cell.countryFlag?.image = UIImage(named : "kenya")
}
if cell.Country!.text! == "Namibia"{
cell.countryFlag?.image = UIImage(named : "namibia")
}
if cell.Country!.text! == "South Africa"{
cell.countryFlag?.image = UIImage(named : "south_africa")
}
else{
cell.countryFlag?.image = UIImage(named : "unknown")
}
return cell
}
私は彼らのすべてが正しい、資産フォルダ内の画像の名前をチェックしていると私は国の名のために入れている条件は名前が私の中に表示される国をもcorrect.Allさに注意してください。テーブルビューセル。
アフリカの画像のコンセントを確認してください。セルクラス – iUser
私のイマgeがロードされているがif条件に従っていない場合は、直接else条件に行き、 "unknown"イメージをロードしています –
最後のセルのみが目的のイメージに従ってロードされています –