gpt4 book ai didi

ios - cellForRow 返回 nil - swift 3

转载 作者:行者123 更新时间:2023-11-28 10:15:42 29 4
gpt4 key购买 nike

我正在调用 JSON 并将数据保存在数组中,然后重新加载 tableView,当我使用 dequeueReusableCell 时一切正常,但是当我更改为 cellForRow每次我设置单元格时都会崩溃。我使用 cellForRow 的原因是我需要在用户点击后更改单元格的图像,但如果我使用 dequeueReusableCell我得到了多项更改(因为单元格总是被重复使用)。

我在 let cell = tableView.cellForRow(at: indexPath) as! TicketTableViewCell 遇到了崩溃.我已经进行了搜索,但没有任何帮助。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.cellForRow(at: indexPath) as! TicketTableViewCell

//let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TicketTableViewCell

cell.date.text = arrDate[indexPath.row].date

//Top Bottom Space.
let maskLayer = CAShapeLayer()
let bounds = cell.bounds
maskLayer.path = UIBezierPath(roundedRect: CGRect(x: 2, y: 2, width: bounds.width-4, height: bounds.height-4), cornerRadius: 2).cgPath
cell.layer.mask = maskLayer

return cell
}

最佳答案

回到使用 dequeueReusableCell

didSelectRowAt更改您要使用的图像,或在数据集中的某处设置一个值,然后重新加载该行

确保 cellForRowAt方法使用您设置的更新图像或标志,并重绘单元格。

关于ios - cellForRow 返回 nil - swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41898389/

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