简体   繁体   中英

How to disable UICollectionViewCell when UICollectionview is scrolling in swift 3

I want to disable UICollectionViewCell Selection when UICollectionView is scrolling. The problem is, I'm trying to set cell.isSelected in didSelectItemAt , but as I've written cell behavior of selection and deselection it's not working.

override var isSelected: Bool {
    didSet {

        if isSelected {
          //selection Code 
        else{
         //deselection Code
        }
}

UPDATE: I want to stop selection while scrolling beacause, consider event when I tap on cell but didn't released my tap. Instead I scroll and released. In this scenario what collectionView doing is, it first call didSelect(I've written code which performs deselection if cell is already selected). So in this case collectionView performs deselection till my tap is ongoing on cell, causing to deselection of cell, but when I scroll and release the tap from collectionView it selects the cell again as it knew the event was actually "scroll" but not the "tap".

Why are you setting isSelected in didSelect() method,

didSelect() method is called only when you have selected a collectionViewCell item, in case you have to work with deselection then you can write that code in didDeselect()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM