Ios 根据collectionView.tag定义collectionView

Ios 根据collectionView.tag定义collectionView,ios,swift,tags,uicollectionview,Ios,Swift,Tags,Uicollectionview,我想编辑collectionView中的单元格,但是因为这是嵌套的collectionView,所以有多个实例 假设我们有indexPath[0,1],那么下面的代码行将该单元格设置为collectionView每个实例中的第一个单元格 if let cell = self?.collectionView.cellForItem(at: indexPath) as? myCustomCell { 因此,我在这里所做的任何操作都将在collectionView的所有实例中对indexOath[0

我想编辑collectionView中的单元格,但是因为这是嵌套的collectionView,所以有多个实例

假设我们有indexPath[0,1],那么下面的代码行将该单元格设置为collectionView每个实例中的第一个单元格

if let cell = self?.collectionView.cellForItem(at: indexPath) as? myCustomCell {
因此,我在这里所做的任何操作都将在collectionView的所有实例中对indexOath[0,1]执行

if let cell = self?.collectionView.cellForItem(at: indexPath) as? myCustomCell {
您可以使用collectionView.tag将数据放入collectionView任何实例的单元格中:

cell.image.image = myArray[collectionView.tag][indexPath.item].image
但是我如何根据它的标记定义collectionView,这样我就可以单独访问该实例了。我想不出这种理想情况下的语法:

let myCVInstance = self?.collectionView.tag(1)
if let cell = myCVInstance.cellForItem(at: indexPath) as? myCustomCell {
因此,我们只能访问嵌套collectionView的第一个实例

if let cell = self?.collectionView.cellForItem(at: indexPath) as? myCustomCell {

谢谢你的提示我问了一个最愚蠢的问题

只需检查标签号,然后如果它是您想要做的事情:

if self?.collectionView.tag == myTag {
// do stuff
}