【发布时间】:2019-11-14 15:24:19
【问题描述】:
只能声明实例方法@IBAction - 这是什么意思?
【问题讨论】:
-
因为一个动作的目标必须是一个对象,也就是一个类的实例。因此,方法(动作)必须声明为实例方法。
只能声明实例方法@IBAction - 这是什么意思?
【问题讨论】:
意味着你不能使class/static方法@IBAction可能是
@IBAction class func aaaa() { // Error here
////
}
【讨论】:
实例方法就是人们通常所说的“方法”。
class myVC: UIViewcontroller {
//this won't work
@IBAction static func buttonTapped(_ sender: UIButton) {
//...
}
//whereas this will
@IBAction func buttonTapped(_ sender: UIButton) {
//...
}
}
【讨论】: