我在button action
以下
@IBAction func actionB(_ sender: UIButton) {
print("something")
}
我想在按钮动作下面调用上面的按钮动作。
@IBAction func actionC(_ sender: UIButton) {
//call to above button action in here
}
我怎样才能做到这一点。希望你对此有所帮助
试试这个 :
@IBAction func actionC(sender: AnyObject) {
//call to above button action in here
actionB(sender: sender);
}
尝试此解决方案
actionB("")
如果你想要你也可以这样做
actionB(sender)
要么
actionB(ButtonB)
只需将您的代码更改为:
@IBAction func actionB(sender: AnyObject?) {
print("something")
actionC(nil)
}
@IBAction func actionC(sender: AnyObject?) {
//call to above button action in here
}
注意AnyObject之后的可选标记。
要么
@IBAction func actionB(sender: AnyObject) {
print("something")
}
@IBAction func actionC(sender: AnyObject) {
//call to above button action in here
actionB("" as AnyObject)
}
这是做到这一点的方法......
@objc fileprivate func methodA(_ sender: UIButton) {
print("method A")
}
@objc fileprivate func methodB(_ sender: UIButton) {
methodA(sender)
}