'#selector' 指的是一个没有暴露给 Objective-C 的方法 [英] '#selector' refers to a method that is not exposed to Objective-C

查看:20
本文介绍了'#selector' 指的是一个没有暴露给 Objective-C 的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 addTarget 传递参数的新 Xcode 7.3 通常对我有用,但在这种情况下,它会在标题中抛出错误.有任何想法吗?当我尝试将其更改为 @objc

The new Xcode 7.3 passing the parameter via addTarget usually works for me but in this case it's throwing the error in the title. Any ideas? It throws another when I try to change it to @objc

谢谢!

cell.commentButton.addTarget(self, action: #selector(FeedViewController.didTapCommentButton(_:)), forControlEvents: UIControlEvents.TouchUpInside)

它调用的选择器

func didTapCommentButton(post: Post) {
}

推荐答案

就我而言,选择器的功能是 private.一旦我删除了 private 错误就消失了.fileprivate 也是如此.

In my case the function of the selector was private. Once I removed the private the error was gone. Same goes for fileprivate.

在 Swift 4 中
您需要将 @objc 添加到函数声明中.在 swift 4 之前,这是隐式推断的.

In Swift 4
You will need to add @objc to the function declaration. Until swift 4 this was implicitly inferred.

这篇关于'#selector' 指的是一个没有暴露给 Objective-C 的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆