【问题标题】:How to call for button action, inside from another button action in swift 3.0如何在 swift 3.0 中从另一个按钮操作中调用按钮操作
【发布时间】:2017-02-26 04:17:03
【问题描述】:

我下面有button action

@IBAction func actionB(_ sender: UIButton) {
 print("something")
}

我想在下面的按钮操作中调用上面的按钮操作。

@IBAction func actionC(_ sender: UIButton) {
 //call to above button action in here
}

我该怎么做。希望您对此有所帮助

【问题讨论】:

  • self.actionB(BUTTONB_OUTLET) 。在您的 actionC 方法中使用此代码
  • @IBAction func actionC(sender: AnyObject) { //在这里调用上面的按钮操作 self.actionB(UIButton) }

标签: ios uibutton swift3 ibaction


【解决方案1】:

试试这个:

 @IBAction func actionC(sender: AnyObject) {
        //call to above button action in here
        actionB(sender: sender);
    }

【讨论】:

    【解决方案2】:

    试试这个解决方案

    actionB("")
    

    如果你愿意,你也可以这样做

    actionB(sender)
    

    actionB(ButtonB)

    【讨论】:

      【解决方案3】:

      只需将您的代码更改为:

      @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)
      }
      

      【讨论】:

        【解决方案4】:

        这是实现它的方法......

        @objc fileprivate func methodA(_ sender: UIButton) {
            print("method A")
        }
        
        @objc fileprivate func methodB(_ sender: UIButton) {
            methodA(sender)
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-07-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-10-26
          相关资源
          最近更新 更多