您好,在我的应用程序中,我想在 cell.contentview 中添加特定 View ,现在的情况是我可以添加此代码。原因是,如果我将此代码放在 cellforitematindexpath 上,它将添加到最后一个单元格(indxpath.row)中,原因是在 cellforrowatindexpath 中,最后一个单元格将最后加载,因此 View 将添加到最后一个单元格中。虽然我希望它出现在当前显示的单元格上
这是我的代码。只需添加 subview
let cell : pdfImageCell = collectionView.dequeueReusableCell(withReuseIdentifier: "pdfImageCell", for: indexPath) as! pdfImageCell
cell.contentView.addSubview(userResizableView1)
最佳答案
在 UICollectionView
中获取可见单元格索引,如下所示。您还可以让多个单元格可见(如果它们在屏幕上可见),因此选择您想要的单元格。
var visibleCurrentCell: IndexPath? {
for cell in self.collectionView.visibleCells {
let indexPath = self.collectionView.indexPath(for: cell)
return indexPath
}
return nil
}
然后从索引中获取单元格并在该单元格中添加 subview 。
关于ios - 如何在uicollectionview中获取当前的cell.contentview。如何在 uicollectionview 单元格中添加 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41518102/