[英]cell selection of UICollectionView does not work in swift
I have written sample code here - when i tap button "Select" it should select all the cells of UICollectionView. 我在这里编写了示例代码-当我点击“选择”按钮时,应该选择UICollectionView的所有单元格。 But is does not work and no error is reported. 但是是不起作用,也没有错误报告。 Below is code 下面是代码
// collectionView is name of UICollectionView // collectionView是UICollectionView的名称
let collectonViewCount = collectionView.numberOfItemsInSection(0);
for i in 0...collectonViewCount {
let indexPath = NSIndexPath(forRow: i, inSection: 0)
collectionView.selectItemAtIndexPath(indexPath, animated: true, scrollPosition: .None)
}
I'm not sure what could be wrong in the above code. 我不确定上述代码中可能出什么问题。
cybergeeeek, cybergeeeek,
you can try 你可以试试
for i in 0...collectonViewCount {
let indexPath = NSIndexPath(forRow: i, inSection: 0)
collectionView.delegate?.collectionView!(collectionView, didSelectItemAtIndexPath: indexPath)
}
This answer ofcourse assumes that you have set the collectionView delegate and have implemented didSelectItemAtIndexPath
this will select the collectionView cell and will trigger didSelectItemAtIndexPath :) 当然,此答案假设您已设置collectionView委托并实现didSelectItemAtIndexPath
这将选择collectionView单元格并触发didSelectItemAtIndexPath :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.