簡體   English   中英

嘗試調用長按手勢並運行命令,但在函數中的選擇器中遇到 SIGABRT 錯誤。 什么沒有連接?

[英]Trying to call a long tap gesture and run a command but running into a SIGABRT error with the selector in the function. What isn't connected?

我的代碼:

override func viewDidLoad() {
    super.viewDidLoad()

    //Adding the long gesture
    let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(longTap))

    //Adding the gesture to the button
    hydrogenBoxButton.addGestureRecognizer(longGesture)

    //Adding a tag for the button
    hydrogenBoxButton.tag = 1
}

然后我的函數在選擇器中被調用:

 @objc func longTap(sender: UIButton) {

        if sender.tag == 1 {
            print("Hydrogen long tap worked!")
        } else if sender.tag == 2 {
            print("Helium long tap worked!")
        }
    }

但是,當我運行它並嘗試長按按鈕時,我收到此錯誤:

-[UILongPressGestureRecognizer 標簽]:無法識別的選擇器發送到實例 0x7fbc5ce00680

我不知道是因為我命名標簽錯誤還是因為我創建 LongPressGestureRecognizer 的方式。

參數的類型為UILongPressGestureRecognizer

@objc func longTap(sender: UILongPressGestureRecognizer ) {
        let tag = sender.view!.tag
        if tag == 1 {
            print("Hydrogen long tap worked!")
        } else if tag == 2 {
            print("Helium long tap worked!")
        }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM