すべてのセルを取得するにはどうすればcollectionView
? collectionView
にはメソッドindexForVisibleItem
しかありません。画面に表示されるセルは選択できますが、不可視なセルにはアクセスできません。たとえば、メソッドを使用しようとすると、collectionView
に50個のイメージがありますが、イメージは24個しかありません。 CollectionView
で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個の細胞をdislay場合おかげで
いいえ - セルは実際には存在しません。あなたは実際に何を達成しようとしています、どうしてなぜ細胞が必要ですか?それらをすべて選択してマークするだけですか?また、dequeueReusableCellWithReuseIdentifierをコレクションデリゲート関数の外で呼び出すことはありません... – Wain
私はボタンをすべて選択する必要があります。私は写真のボールトを持っています。すべての画像を選択することができます(すべてのセル(画像)を取得できます)どのようなアルバムのすべての画像を削除するようないくつかのタスクどのように私はこの作業を達成することができますか? –
このリンクをチェックすると役立つかもしれないhttp://stackoverflow.com/questions/19916900/selecting-all-the-items-in-uicollectionview-ios-even-the-cells-that-are-not-vis –