我正在更改tableViewCell
中某個視圖的背景顏色,但它在第一次加載時不會更改,我需要滾動才能看到更改。這是我的手機類:在tableview單元格中更改視圖的顏色不會更改
@IBOutlet weak var status_back: UIView!
@IBOutlet weak var status_label: UILabel!
@IBOutlet weak var node_label: UILabel!
@IBOutlet weak var time_label: UILabel!
@IBOutlet weak var name_label: UILabel!
@IBOutlet weak var res_date: UILabel!
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func layoutSubviews() {
status_back.layer.cornerRadius = status_back.frame.height/2
}
和改變status_back的顏色的ViewController代碼:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "MealCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! ReservationCell
let reservation = filteredreservations[(indexPath as NSIndexPath).row]
cell.name_label.text = "نام: "+reservation.client_name
cell.name_label.font = UIFont(name: "WeblogmaYekan", size: 17)
cell.time_label.text="زمان: "+reservation.ft_of_time+"-"+reservation.ft_to_time
cell.time_label.font = UIFont(name: "B Yekan", size: 17)
cell.res_date.text="تاریخ: \(reservation.date)"
cell.res_date.font = UIFont(name: "B Yekan", size: 17)
var status = ""
if reservation.type {
cell.node_label.text="ex1 \(reservation.node_title)"
} else {
cell.node_label.text="ex2"
}
switch reservation.res_status {
case "CanceledByAdmin":
cell.status_back.backgroundColor=Utils.UIColorFromRGB(rgbValue: 0xFFFC635D)
status = "ex"
case "Canceled":
cell.status_back.backgroundColor=Utils.UIColorFromRGB(rgbValue: 0xFFEE903D)
status = "ex"
case "Deprecated":
cell.status_back.backgroundColor=Utils.UIColorFromRGB(rgbValue: 0xFF757575)
status = "ex"
default:
cell.status_back.backgroundColor=Utils.UIColorFromRGB(rgbValue: 0xFF3BA757)
status = "ex"
}
cell.status_label.text=status
cell.status_label.font = UIFont(name: "WeblogmaYekan", size: 17)
return cell
}
是'cellForRowAtIndexPath'裏面的代碼? –
是的,我確定@NiravD –