Swift 获取collectionView中的所有单元格
如何获取Swift 获取collectionView中的所有单元格,swift,uicollectionview,Swift,Uicollectionview,如何获取collectionView中的所有单元格? collectionView只有一个方法indexForVisibleItem,我只能选择屏幕上显示的单元格,但无法访问不可见的单元格。例如,我在collectionView中有50个图像,当我尝试使用indexForVisibleItem方法时,我只得到24个图像。如何在CollectionView中选择所有单元格50图像?我有什么办法可以完成这项任务吗 我的代码: @IBAction func selectAllActionBtn(sen
collectionView
中的所有单元格?
collectionView
只有一个方法indexForVisibleItem
,我只能选择屏幕上显示的单元格,但无法访问不可见的单元格。例如,我在collectionView
中有50个图像,当我尝试使用indexForVisibleItem
方法时,我只得到24个图像。如何在CollectionView
中选择所有单元格50图像?我有什么办法可以完成这项任务吗
我的代码:
@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
}
}
感谢advance如果您的collectionView显示24个单元格,则表示collection view中只有24个单元格 如果您想全部检查,我认为您应该实现如下单元模式
class cellMode{
......
var status = false
......
}
当选择/取消选择全部时,更改单元格的状态并重新加载collectionview。否-单元格实际上不存在。你到底想达到什么目的,为什么你还需要细胞呢?只是为了将它们全部标记为选中?另外,切勿在集合委托功能之外调用
dequeueReusableCellWithReuseIdentifier
…我需要让按钮选择所有我有的应用程序照片库我需要让用户能够选择所有图像(获取内容所有单元格(图像))对于一些任务,如删除任何相册中的所有图像,我如何才能完成此任务?检查此链接可能会对您有所帮助非常感谢我将检查此链接中的代码不起作用?你有其他的方法来完成这个任务吗?非常感谢,你能给我举个例子吗