2016-07-02 3 views
2

すべてのセルを取得するにはどうすればcollectionViewcollectionViewにはメソッド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場合おかげで

+0

いいえ - セルは実際には存在しません。あなたは実際に何を達成しようとしています、どうしてなぜ細胞が必要ですか?それらをすべて選択してマークするだけですか?また、dequeueReusableCellWithReuseIdentifierをコレクションデリゲート関数の外で呼び出すことはありません... – Wain

+0

私はボタンをすべて選択する必要があります。私は写真のボールトを持っています。すべての画像を選択することができます(すべてのセル(画像)を取得できます)どのようなアルバムのすべての画像を削除するようないくつかのタスクどのように私はこの作業を達成することができますか? –

+0

このリンクをチェックすると役立つかもしれないhttp://stackoverflow.com/questions/19916900/selecting-all-the-items-in-uicollectionview-ios-even-the-cells-that-are-not-vis –

答えて

0

を進め、それが唯一の24の細胞がコレクションビューにあることを意味します。あなたはすべてをチェックしたい場合は

は、私はあなたが以下の

class cellMode{ 
    ...... 
    var status = false 
    ...... 
} 

変化として、細胞の状態をセルモードを実装し、選択/すべての選択を解除collectionviewをリロードするべきだと思います。

+0

ありがとう、私に例を挙げてもらえますか? –

関連する問題