Ios 在collectionview上显示复选标记

Ios 在collectionview上显示复选标记,ios,swift,swift3,uicollectionview,Ios,Swift,Swift3,Uicollectionview,我有一个收集视图,当点击每个单元格时,会弹出一个更大版本的单元格图像,当再次点击时会消失。除此之外,我希望能够在单元格的角落中选择一个视图,当再次点击时,该视图将显示一个蓝色的复选标记()或一个灰色的复选标记。我目前的代码是: func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell =

我有一个收集视图,当点击每个单元格时,会弹出一个更大版本的单元格图像,当再次点击时会消失。除此之外,我希望能够在单元格的角落中选择一个视图,当再次点击时,该视图将显示一个蓝色的复选标记()或一个灰色的复选标记。我目前的代码是:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as! PhotoCell

    cell.backgroundColor = .clear
    cell.imageView.image = UIImage(contentsOfFile: imagesURLArray[indexPath.row].path)
    cell.checkmarkView.checkMarkStyle = .GrayedOut
    cell.checkmarkView.tag = indexPath.row
    cell.checkmarkView.checked = false

    let tap = UITapGestureRecognizer(target: self, action: #selector(checkmarkWasTapped(_ :)))
    cell.checkmarkView.addGestureRecognizer(tap)

    return cell
}

func checkmarkWasTapped(_ sender: SSCheckMark) {

    let indexPath = IndexPath(row: sender.tag, section: 1)

    if sender.checked == true {
        sender.checked = false
    } else {
        sender.checked = true
    }
    collectionView.reloadItems(at: [indexPath])
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    addZoomedImage(indexPath.row)
    addGestureToImage()
    addBackGroundView()

    view.addSubview(selectedImage)
}
但是,当我运行并选择复选标记视图时,会出现错误:


无法识别的选择器发送到实例
checkmarkWasTapped()
的第一行,我可以看到它不喜欢sender,但我不知道为什么。任何帮助都会很好。

uitappesturerecognizer
点击
“发送人”就是这个手势。
复选标记被点击
方法定义错误。您可以使用
sender.view
获取
checkmarView
。试试这个

func checkmarkWasTapped(_ sender: UIGestureRecognizer) {

    let checkmarkView= sender.view as? SSCheckMark

    let indexPath = IndexPath(row: checkmarkView.tag, section: 1)

    if checkmarkView.checked == true {
        checkmarkView.checked = false
    } else {
        checkmarkView.checked = true
    }
    collectionView.reloadItems(at: [indexPath])
}

太好了,谢谢。你知道为什么要两次点击支票才会出现和消失吗?