如何在 swift 3.0 中从另一个按钮操作中调用按钮操作

How to call for button action, inside from another button action in swift 3.0

我有以下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)
}