ios - Trying to override "selected" in UICollectionViewCell Swift for custom selection state -


i trying implement custom selection style cells in uicollectionview. though possible manually in didselect , diddeselect methods achieve manipulating "selected" variable in uicollectionviewcell.

i have code it:

    override var selected: bool {     {         return super.selected     }     set {         if newvalue {             self.imageview.alpha = 0.5             println("selected")         } else if newvalue == false {             self.imageview.alpha = 1.0             println("deselected")         }     } } 

now, when select cell, cell gets highlighted "selected" gets printed twice , deselection not work (even though both uicollectionview methods implemented).

how go this? thanks!

figured out stepping code. problem super.selected wasn't being modified. changed code this:

override var selected: bool {     {         return super.selected     }     set {         if newvalue {             super.selected = true             self.imageview.alpha = 0.5             println("selected")         } else if newvalue == false {             super.selected = false             self.imageview.alpha = 1.0             println("deselected")         }     } } 

now it's working.


Comments