我有一个 tableView 来显示工作日的时间
在tableView中使用timingsArray来显示计时
timingObj 类型的timingsArray
class timingObj {
var dayNo: Int?
var open: String?
var close: String?
var dayName: String?
init(json: JSON){
// to take data from json
}
init(name: String, number: Int){
self.dayName = name
self.dayNo = number
}
}
在 tableView 中,我想显示所有日期及其时间,如果这一天没有时间,那么时间单元格将为空
let cell = tableView.dequeueReusableCellWithIdentifier("TimingsCell", forIndexPath: indexPath) as! timingCell
let timings = self.Details!.timingsArray
let dayTime = timings[indexPath.row]
cell.dayLabel.text = dayTime.dayName
if dayTime.open != nil && dayTime.close != nil {
cell.timeLabel.text = "\(convertTimeFormat(dayTime.open!)) - \(convertTimeFormat(dayTime.close!))"
}
return cell
这是细胞的类别
class timingCell: UITableViewCell {
@IBOutlet weak var dayLabel: UILabel!
@IBOutlet weak var timeLabel: UILabel!
}
例如周二和周四只有时间
问题是当我上下滚动时,星期二的计时值会在星期三重复,而当我继续滚动时,其他单元格中的计时值也会重复
有任何想法吗?先感谢您
你应该实施prepareForReuse
在您的自定义单元格类中,您可以在其中重置需要重置的内容。例如:
class timingCell: UITableViewCell {
@IBOutlet weak var dayLabel: UILabel!
@IBOutlet weak var timeLabel: UILabel!
func prepareForReuse() {
super.prepareForReuse()
cell.timeLabel.text = nil
cell.dayLabel.text = nil
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)