【发布时间】:2020-03-03 17:40:13
【问题描述】:
你好!问题是我无法用数据填充我的表格视图。尽管在某种程度上它是正确的,但我意识到程序一次又一次地将一个视图置于另一个视图之上。下面,我提供了与问题绝对相关的代码片段
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if cell.isHidden == true {
cell.isHidden.toggle()
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let record = records[indexPath.section][indexPath.row]
let view = RecordView(price: record.price, place: record.place, time: record.date?.getDay(), category: record.category)
let cell = tableView.dequeueReusableCell(withIdentifier: "RecordViewCell", for: indexPath) as! RecordViewCell
cell.setRecordView(record: view)
cell.clipsToBounds = true
cell.contentView.backgroundColor = UIColor.clear
cell.layer.backgroundColor = UIColor.clear.cgColor
cell.backgroundColor = .clear
return cell
}
还有,
class RecordViewCell: UITableViewCell {
@IBOutlet weak var view: UIView!
func setRecordView(record: RecordView) {
view.addSubview(record)
record.frame = CGRect(x: 5, y: 5, width: view.frame.width - 10, height: 60)
}
override func prepareForReuse() {
super.prepareForReuse()
self.isHidden = true
}
}
非常感谢您。
【问题讨论】:
-
图片到底有什么问题?我不确定预期的行为是什么。
isHidden的魔法可能根本不需要。
标签: ios swift uitableview swift5