2015-08-28 75 views
0

我試圖取消選擇以前選擇的但在集合視圖中當前不可見的單元格。我使用此代碼:取消選擇當前不可見的單元格

 let optionalSelectedItems = collectionView.indexPathsForSelectedItems() 
     if let selectedItems = optionalSelectedItems{ 
     for indexPath in selectedItems{ 

     self.collectionView.deselectItemAtIndexPath(indexPath, animated: true) 
     self.collectionView.delegate?.collectionView!(self.collectionView, didDeselectItemAtIndexPath: indexPath) 
     } 

有我的執行func collectionView(_:didDeselectItemAtIndexPath:)正在進行一些非常重要的東西。取消選擇在其他視圖中觸發事件。 這會引發錯誤,因爲我取消選擇當前不在屏幕中的單元,因此甚至不在內存中。如何在短時間內將細胞放入記憶中?我只需要取消選擇它們,所以我猜0.1s就足夠了。

+0

我與'UITableView'類似的問題選擇/取消選擇創建後細胞;該解決方案是調用'super.tableView:deselectRowAtIndexPath:'。 –

+0

一些非常重要的事情發生在我的實現collectionView(_:didDeselectItemAtIndexPath :),它需要被稱爲 – brumbrum

回答

1

可以存儲在單獨的陣列選定行的索引和在

func collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell 
+0

我按下特定的按鈕時取消選擇所有單元格。如果我錯了,請糾正我,但永遠不會調用該方法,因爲只有當單元格變爲可見時纔會調用該方法。 – brumbrum

+0

那麼如何觸摸單元格上的「當前不可見」按鈕? – Igor

+0

該按鈕不是一個單元格。這是一個普通的UIButton實例,在集合視圖之外的某處。 – brumbrum

相關問題