gpt4 book ai didi

ios - 如何使用原始索引路径从数组中删除对象?

转载 作者:行者123 更新时间:2023-11-28 13:12:47 24 4
gpt4 key购买 nike

我有一个 UICollectionView,用户可以在其中从单元格中选择数据以添加到数组中。我试图在点击时突出显示选定的单元格,并在再次点击时取消突出显示它们。在突出显示和取消突出显示的同一段代码中,我想从数组中添加/删除数据。将数据添加到数组中没有问题,但我不知道如何在未突出显示时将其删除。

代码在这里:

var removeFromList = [AnyObject]()
func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool {

var cell = self.collectionView2.cellForItemAtIndexPath(indexPath)

if cell!.tag == 0 {
cell!.layer.borderWidth = 2.0
cell!.layer.borderColor = UIColor.blueColor().CGColor
removeFromList.append(objectIds[indexPath.row])
cell!.tag = 1
} else {
cell!.layer.borderWidth = 0.0
cell!.tag = 0
removeFromList.//WHAT CAN I PUT HERE?
}
return true
}

最佳答案

使用removeAtIndex(index: Int)方法移除一个项目

var removeFromList = [NSString]()

if let index = find(removeFromList, objectIds[indexPath.row] as! NSString) {
removeFromList.removeAtIndex(index)
}

关于ios - 如何使用原始索引路径从数组中删除对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30681894/

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