gpt4 book ai didi

iOS swift : TableViewCell not being drawn properly

转载 作者:搜寻专家 更新时间:2023-11-01 05:42:01 25 4
gpt4 key购买 nike

我遇到了一个奇怪的错误,即 tableViewCell 页脚在启动时未正确绘制。但是一旦细胞被回收,它们就会按预期出现。这是一个屏幕录像(注意回收后顶部单元格页脚的显示方式):https://www.dropbox.com/s/tw1le35ppaim3yb/Recording.mov?dl=0

ViewController.swift

override func viewDidLoad() {
super.viewDidLoad()

tableView.registerClass(TableCell.self, forCellReuseIdentifier: "Cell")
tableView.delegate = self
tableView.dataSource = self
view.addSubview(tableView)
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:TableCell = tableView.dequeueReusableCellWithIdentifier("Cell") as TableCell
let data = items[indexPath.row]
cell.date.text = data.creationDate.description
return cell
}

TableCell.swift

class TableCell: UITableViewCell {

let date = UILabel()

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(date)
}

override func layoutSubviews() {
superview?.layoutSubviews()
date.frame = CGRectMake(10, 10, frame.width, 30)
}
}

最佳答案

问题出在我的重写 layoutSubviews 我没有调用 super.layoutSubviews()

关于iOS swift : TableViewCell not being drawn properly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28144393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com