[英]Set effect on selected cell in uicollectionview(single selection) ios swift
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
你只需要处理
didDeselect
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath)
And of course have set single selection on your collection view 当然,在您的集合视图中设置了单一选择
collectionView.allowsMultipleSelection = false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.