我在单UITableViewCell
中有两种设计。这是我想要的设计,并在加载viewController
我认为这个问题是由UITableViewCell的可重用性引起的。这是我的cellForRowAtIndexPath代码
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "notificationCell", for: indexPath) as! NotificationTableViewCell
cell.selectionStyle = .none
cell.btnClose.tag = indexPath.row
let noti_flag = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "noti_flag") //as! String
let noti_flag_string = NSString(format: "%@", noti_flag as! CVarArg) as String
cell.lbl_From.text = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "caller_id") as? String ?? ""
if noti_flag_string == "0" {
cell.lblTime.isHidden = true
cell.imgThumbIcon.isHidden = true
cell.lbl_remaining.isHidden = true
cell.lbl_mm_text.text = "Missed call"
cell.lbl_mm_text.font = cell.lbl_mm_text.font.withSize(23)
}
else{
var startAttributedText = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "rebound_start_time") as! String
var endAttributedText = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "rebound_end_time") as! String
startAttributedText = Model.shared.convertLocalTimeToServer(timeString: startAttributedText,isTimeFromServer: true)
endAttributedText = Model.shared.convertLocalTimeToServer(timeString: endAttributedText,isTimeFromServer: true)
let dateString:String = startAttributedText + " - " + endAttributedText
cell.lblTime.attributedText = convertStringToAttr(dateString: dateString)
cell.lbl_remaining.text = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "remaining_time") as? String ?? ""
cell.lbl_mm_text.text = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "mm_text") as? String ?? ""
//cell.lbl_From.text = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "caller_id") as? String ?? ""
let mm_type = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "mm_type") as! String//"img"
switch mm_type {
case "img":
cell.imgThumbIcon.image = UIImage(named: "thumb_camera")
case "vid":
cell.imgThumbIcon.image = UIImage(named: "thumb_video")
case "aud":
cell.imgThumbIcon.image = UIImage(named: "thumb_audio")
case "str":
cell.imgThumbIcon.image = UIImage(named: "thumb_sticker")
case "txt":
cell.imgThumbIcon.image = UIImage(named: "thumb_text")
case "brd":
cell.imgThumbIcon.image = UIImage(named: "thumb_brand")
default:
cell.imgThumbIcon.image = UIImage(named: "thumb_camera")
}
}
return cell
}
所以请帮我解决这个问题。提前致谢。