在我的旧Swift iOS应用程序项目中,我使用的代码如下:
button!.addTarget(self,action:"ratingButtonTapped:",for:.touchDown)
其中 ratingButtonTapped 是同一类中的函数
代码转换器给出错误
"没有用Objective-C选择器声明的方法' ratingButtonTapped:'"
然后建议这个解决方案 !按钮.addTarget(个体,动作:选择器(" ratingButtonTapped:&#34),用于:.touchDown)
唯一的问题是即使在应用修复后,它仍会继续发出警告
"没有用Objective-C选择器声明的方法' ratingButtonTapped:'"
然后建议将其包装在括号中以隐藏警告
...
这是我在同一个分类中的函数声明:
func ratingButtonTapped(_ sender: UIButton) {
}
...
我想我在Swift 3中做过这种日期和错误的方式 - 但是正确的方法是什么呢?该类有一个名为 ratingButtonTapped
的函数答案 0 :(得分:1)
button.addTarget(self, action: #selector(YourClassController. ratingButtonTapped(_:)), for: .touchUpInside)
func ratingButtonTapped(_ sender:UIButton){
}