首页 > 解决方案 > Swift 4.2 - 此类与 UITapGestureRecognizer 上的键的键值编码不兼容

问题描述

我有一个像这样的 UITapGestureRecognizer:

let tap = UITapGestureRecognizer(target: self, action: #selector(self.commentsPressed))

self.comments.addGestureRecognizer(tap)

self.comments 是一个 UILabel 和 self.commentsPressed 看起来像这样:

@objc func commentsPressed(recognizer: UITapGestureRecognizer) {

        let viewController = storyboard?.instantiateViewController(withIdentifier: "Comments") as! CommentsController

        viewController.postid = postid

        viewController.disabled = self.commentsDisabled

        viewController.userid = self.userid

        viewController.coverImageString = self.coverImageString

        self.navigationController?.pushViewController(viewController, animated: true)

    }

但是当我按下我的 UILabel 时,我得到了这个错误:

此类与键 commentButton 的键值编码不兼容。

在我将代码转换为 Swift 4.2 之前,这是有效的,现在它突然不工作了,我做错了什么,我该如何解决?

标签: iosswift

解决方案


推荐阅读