0
我有快速集合視圖和項目,我想添加每個項目點擊數組和相同的項目時再次單擊將被刪除數組中。我的代碼在這裏。Swift集合視圖didSelectItemAtIndexPath單擊時添加/刪除數組
我的陣列
var services = [""]
我didSelectItemAtIndexPath碼
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let clickeditem = items[indexPath.section].services[indexPath.item - 1]
print(clickeditem) // here clicked item this item will be add to services array when first click, after clicked again will be remove in services array
}
clickeditem //將添加到服務陣列時,第一次點擊,點擊後會再次在服務數組中刪除