2016-07-18 2 views
2

ボタンがありますこのボタンはcollectionViewのすべてのセルを選択していますが正常ですが問題はすべてのセルを選択すると大容量のメモリが取れますなぜ私に教えてくださいどのように私はcollectionviewCellでselect allの問題が発生しました

次の私のコードの巨大なメモリを取ることなく、collectionViewのすべてのセルを選択することができます。

FUNCのselectAllCells(){

    var i = 0 
       while i < self.collectionView.numberOfItemsInSection(0) { 
       // her i get the index path 
       let indexPath = NSIndexPath(forItem: i, inSection: 0) 
       self.collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: false) 

       self.collectionView.decelerationRate = UIScrollViewDecelerationRateFast 
       self.collectionView.reloadItemsAtIndexPaths([indexPath]) 
       self.dictionaryOfSelectItem.updateValue(i, forKey: i) 
       let cell = self.collectionView.cellForItemAtIndexPath(indexPath) as! AlbumImagesCollectionViewCell 
       cell.imageViewCheck.hidden = false 
       self.dictionaryOfSelectItem.updateValue(i, forKey: i) 

       i = i + 1 

       } 

       self.moveOutlet.enabled = true 
       self.exportOutlet.enabled = true 
       self.deleteOutlet.enabled = true 


} 

おかげで進める

答えて

1

selectAllというグローバル変数を、viewDidLoad()の前のどこかに作成します。

selectAll()関数の中で、作成した変数をtrueに設定します。あなたのcellForItemAtIndexPathで今

self.selectAll = true; 
//Now call your reload function for your collectionView. 
self.collectionView.reloadData 

ユーザーがボタン「すべて選択」選択解除、または に何か他のもの、そしてセットのSelectAllを行い、再びデータをリロード
if selectAll { 
     cell.selected = true; 
} else { 
     cell.selected = false; 
} 

すべてのセルが選択された後に、すべてのセルで何かを実行する場合は、cellForItemAtIndexPath関数で行います。

+0

私の友人に感謝しますが、リロード機能を呼び出すと、表示されるか、私の特定の機能が表示されますか教えてください。 –

+0

selectAll()関数内でreload関数を呼び出します。 –

+0

ありがとう –

関連する問題