如何在集合视图中获取索引 path.item - 1 处的单元格
how to get the cell at index path.item - 1 in collection view
如果索引 path.item[=12= 处的单元格满足某些条件,我想访问我的集合视图中的前一个单元格(索引 path.item - 1)以更改那里的一些设置]
现在我试过了:
let previousCell = collectionView.cellForItem(at: indexPath - 1)
但它不起作用,因为 - 1 它从索引路径向下转换为整数值。
如何获取此单元格?
"previous cell" 到底是什么意思?你的意思是同一部分但前一行?然后构造一个比这一行小row
的索引路径。
但是,问题本身似乎表明对 table 视图的工作方式存在完全误解。您根本不需要 "access" 任何单元格。更新您的 模型 并重新加载 table (或相关单元格)。
请检查:
let previousCell = collectionView.cellForItem(at: IndexPath(row: indexPath.row-1, section: indexPath.section))
获取标识符为 :
的单元格
let prevIndexPath = IndexPath(row: indexPath.row-1, section: indexPath.section)
let previousCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: prevIndexPath)
如果索引 path.item[=12= 处的单元格满足某些条件,我想访问我的集合视图中的前一个单元格(索引 path.item - 1)以更改那里的一些设置]
现在我试过了:
let previousCell = collectionView.cellForItem(at: indexPath - 1)
但它不起作用,因为 - 1 它从索引路径向下转换为整数值。
如何获取此单元格?
"previous cell" 到底是什么意思?你的意思是同一部分但前一行?然后构造一个比这一行小row
的索引路径。
但是,问题本身似乎表明对 table 视图的工作方式存在完全误解。您根本不需要 "access" 任何单元格。更新您的 模型 并重新加载 table (或相关单元格)。
请检查:
let previousCell = collectionView.cellForItem(at: IndexPath(row: indexPath.row-1, section: indexPath.section))
获取标识符为 :
的单元格let prevIndexPath = IndexPath(row: indexPath.row-1, section: indexPath.section)
let previousCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: prevIndexPath)