取消选择collectionView并从数组中取消项目

时间:2016-03-30 20:29:58

标签: arrays swift uicollectionview

我有以下代码:

 var selectedIndexPaths = [NSDate]()

    func collectionView(collectionView: UICollectionView,  didSelectItemAtIndexPath indexPath: NSIndexPath) {

        let cell = collectionView.cellForItemAtIndexPath(indexPath) as?  PartExpense

        if cell?.selected == true {
            cell?.layer.borderWidth = 4.0
            cell?.layer.borderColor = UIColor.greenColor().CGColor

            selectedIndexPaths.append(cell!.idPartecipant)

            print(selectedIndexPaths)


        }
    }

    func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
        let cell = collectionView.cellForItemAtIndexPath(indexPath)
        if cell?.selected == false {
            cell?.layer.borderColor = UIColor.clearColor().CGColor


            if let index = selectedIndexPaths.indexOf(indexPath.row) {
                selectedIndexPaths.removeAtIndex(index)
                print(selectedIndexPaths)
            }

        }

    }

一切顺利到行:     if let index = selectedIndexPaths.indexOf(indexPath.row)

这是错误:“无法将Int类型的值转换为期望类型NSDate”如何实现此目的?如何转换数组以避免此错误?

1 个答案:

答案 0 :(得分:0)

您编写的方式是询问该数组中的所有NSDates什么是日期“indexPath.row”的索引。错误是说indexPath.row是一个int而不是一个日期。你究竟想做什么?

相关问题