如何获得所有细胞collectionView
?在collectionView
只有一个方法indexForVisibleItem
,我只能选择出现在屏幕上的细胞,但我不能访问无形的细胞。例如,collectionView
当我尝试使用该indexForVisibleItem
方法时,我只有50张图像,而我只能得到24张图像。如何选择其中包含50张图像的所有单元格CollectionView
?有什么办法可以执行此任务?
我的代码:
@IBAction func selectAllActionBtn(sender: AnyObject) {
dictionaryOfImagesForExport = [:]
dictionaryOfGetImageUrl = [:]
if editing {
let fileManager = NSFileManager.defaultManager()
do {
let document = try fileManager.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
let getFolders = try fileManager.contentsOfDirectoryAtURL(document, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles)
for folder in getFolders {
if folder.lastPathComponent! == albumName {
let getImages = try fileManager.contentsOfDirectoryAtURL(folder, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles)
for index in 0...getImages.count {
let indexP = NSIndexPath(forItem: index, inSection: 0)
let cell = myCollectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexP) as! AlbumImagesCollectionViewCell
for img in getImages {
cell.imageViewCell.image = UIImage(data: NSData(contentsOfURL: img)!)
cell.imageViewCheck.image = UIImage(named: "check.png")
dictionaryOfImagesForExport.updateValue(cell.imageViewCell.image!, forKey: indexP.row)
dictionaryOfGetImageUrl.updateValue(cell.imageUrlLabel.text!, forKey: indexP.row)
}
}
}
}
}catch {
print(error)
}
exportBtn.enabled = true
moveBtn.enabled = true
deleteBtn.enabled = true
}
}
谢谢提前
如果您的collectionView放置24个单元格,则意味着在集合视图中只有24个单元格。
如果您想全部检查,我认为您应该按照以下方式实施单元模式
class cellMode{
......
var status = false
......
}
选择/取消全选时,更改单元格的状态并重新加载collectionview。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句