【发布时间】:2017-04-13 11:46:42
【问题描述】:
我在 Swift 3 中搜索了很多选择器方法,但我对它有很多困惑。
1) Selector 和 #selector 有什么区别?
2)如果我用Selector写,功能被概述意味着不可用?
3) 如何使用#selector 方法传递参数。
我的代码
let button = UIButton()
button.addTarget(self, action: #selector(getData(_:true)), for: .touchUpInside)
button.addTarget(self, action: Selector(), for: .touchUpInside)
func getData(_ isShowing:Bool){
}
你能帮我解开疑惑吗?
感谢您宝贵的时间
【问题讨论】:
-
关于问题3。直接使用
#selector(getData)即可,无需指定参数。 -
@LeoDabus,感谢您的回答,但我必须传递一个值来检查条件。
-
发送者是UIButton,所以把方法参数改成
(_ button: UIButton) -
传递值是什么意思?你不能在选择器中传递
true
标签: ios iphone swift xcode swift3