gpt4 book ai didi

ios - 在uicollectionview(单选)中设置对所选单元格的影响ios swift

转载 作者:搜寻专家 更新时间:2023-10-31 08:23:01 28 4
gpt4 key购买 nike

我正在使用 Collection View 进行水平滚动。它工作得很好。现在我想为选择任何单元格设置任何效果。所以,我写了这段代码”

 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)


}

这会为选定的单元格设置边框。但是,当我选择另一个单元格时,两个单元格都被选中,但我只需要一个选择,这样当用户选择一个单元格时,必须取消选择旧单元格。

最佳答案

你只需要处理didDeselect

func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath)

当然还有在您的收藏 View 中设置单选

collectionView.allowsMultipleSelection = false

关于ios - 在uicollectionview(单选)中设置对所选单元格的影响ios swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34739510/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com