gpt4 book ai didi

ios - UITableView didSelectRowAt 无法获取我的单元格

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

我有一个问题。我有一个 UITableView 和四个自定义 UITableViewCell。
当我滚动到底部时,我也无法在 didSelectRowAt 函数中获取我的自定义 UITableViewCell。
请给我一些建议。
谢谢。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

if let cell: ChartTableViewCell = customTableview.cellForRow(at: IndexPath(row: 0, section: 0)) as? ChartTableViewCell {
printBBLog("here.") //just When I scrolled to bottom, this don't print.
let colors = AssetViewController.Color.getAllColors()
cell.barChartView?.tapIndexWithColor(index: indexPath.row-2, color: colors[indexPath.row-2])
}

}

最佳答案

当请求的单元格当前在屏幕上不可见时,

cellForRow(at:) 将返回 nil。当您的 TableView 滚动到底部时,第 0 行很可能不可见。

但是,您的 if 语句正在发挥作用;如果 cellForRow(at:) 返回 nil,则您没有要更新的单元格,因此您无需在该函数中执行任何操作。

您应该在 cellForRow(at:) 数据源方法中设置第 0 行单元格下次出队时的外观。

而且,正如@Bappaditya 所指出的,您可能会因 indexPath.row-2

发生越界崩溃

关于ios - UITableView didSelectRowAt 无法获取我的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53952844/

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