gpt4 book ai didi

ios - 获取 tableViewCells 中 tableView.visibleCells 的索引

转载 作者:行者123 更新时间:2023-11-29 05:38:07 30 4
gpt4 key购买 nike

我想对可见单元格进行更改,以便它们反射(reflect)对基础业务对象(数组中的对象,与表中单元格的索引和数组中的对象相关)所做的更改。

我只需要找出表中单元格的索引或indexPath。因此,如果有 10 个单元格且下半部分可见,那么我需要将第一个可见单元格的值设置为 5,以将其与文章对象数组中的相同位置相关联。

 for cell in tableView.visibleCells as! [ArticleTableViewCell] {
//do something with the cell here.
// var article = articlesList!.value![cell.index indexPath.item]
cell.lblTitle.text = articleArray[5].title
}

最佳答案

您应该告诉 TableView 重新加载可见单元格,而不是手动迭代和更新可见单元格。这允许您现有的 cellForRowAt 代码完成其工作,而无需在其他地方复制代码。

if let visibleRows = tableView.indexPathsForVisibleRows {
tableView.reloadRows(at: visibleRows, animation: .fade)
}

关于ios - 获取 tableViewCells 中 tableView.visibleCells 的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56827740/

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