I am using collection view for horizontal scrolling. Its working pretty well. Now I want to set any effect for selecting any cell. So, I wrote this code"
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell?.layer.borderColor = .None
cell!.layer.borderWidth = 2.0
cell!.layer.borderColor = UIColor.whiteColor().CGColor
let dic1 = arr.objectAtIndex(indexPath.row) as! NSDictionary
let url = dic1["url"] as! String
let requestURL = NSURL(string:url)
let request = NSURLRequest(URL: requestURL!)
webviewfortab.loadRequest(request)
}
This sets border for selected cell. But, when I select another cell, both the cell are getting selected but I want only single selection so that when user selects one,old one must be disselected.
You just have to handle didDeselect
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath)
And of course have set single selection on your collection view
collectionView.allowsMultipleSelection = false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With