UIView背景颜色在UITableViewCell
内没有立即改变,
当类第一次加载时 StatusTableViewCell
(TableViewCell)
出现具有默认背景颜色的 backgroundStatusCell (UIView)
,
即使执行了 guard
条件,backgroundStatusCell
的背景颜色也不会受到影响。仅当单元格滚动时才会发生。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "StatusTableViewCell") as! StatusTableViewCell
statusViewModel.configurationStatusCell(cell: cell, forRowAtIndexPath: indexPath as NSIndexPath)
guard statusViewModel.progressValues(indexValue: indexPath.row) >= 50 else{
cell.backgroundStatusView.backgroundColor = .blue
return cell
}
cell.backgroundStatusView.backgroundColor =.red
return cell
}
}
最佳答案
试试这个
let cell = tableView.dequeueReusableCell(withIdentifier: "StatusTableViewCell") as! StatusTableViewCell
statusViewModel.configurationStatusCell(cell: cell, forRowAtIndexPath: indexPath as NSIndexPath)
if statusViewModel.progressValues(indexValue: indexPath.row) >= 50
{
cell.backgroundStatusView.backgroundColor =.red
//or
//cell.backgroundColor =.red
}
else{
cell.backgroundStatusView.backgroundColor = .blue
//or
//cell.backgroundColor =.blue
}
return cell
关于ios - UITableViewCell UIView 颜色在类加载时不会立即更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58982439/