gpt4 book ai didi

ios - 获取线程1 : signal sigabrt when trying to use tap gesture recognizer to open url

转载 作者:行者123 更新时间:2023-11-30 12:17:00 27 4
gpt4 key购买 nike

我正在尝试使用点击手势识别器在点击图像时打开 URL。代码构建成功,但当我尝试点击图像时,它终止并显示

terminating with uncaught exception of type NSException (lldb)

在控制台中。控制台还显示

[Hello.ViewController clickToOpen]: unrecognized selector sent to instance.

还有一个

Thread 1: signal SIGABRT

在行

class AppDelegate: UIResponder, UIApplicationDelegate {" in AppDelegate.swift.

ViewController 代码如下:

//
// ViewController.swift
// Hello
//

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

//MARK: Outlets
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var helloName: UILabel!
@IBOutlet weak var imageToTap: UIImageView!

override func viewDidLoad() {
super.viewDidLoad()

nameTextField.delegate = self

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector(("clickToOpen")))
self.imageToTap.addGestureRecognizer(tapGestureRecognizer)
self.imageToTap.isUserInteractionEnabled = true
}

//MARK: UITextFieldDelegate
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// Hide the keyboard
textField.resignFirstResponder()

return true
}
func textFieldDidEndEditing(_ textField: UITextField) {
helloName.text = "Hello \(textField.text!)"
textField.text = ""
}

//MARK: Actions
@IBAction func clearButton(_ sender: UIButton) {
helloName.text = "Hello"
}
@IBAction func enterButton(_ sender: UIButton) {
nameTextField.resignFirstResponder()
}
@IBAction func clickToOpen(_ sender: UITapGestureRecognizer) {
if let url = NSURL(string: "http://www.google.com/") {
UIApplication.shared.openURL(url as URL)
}

}

}

最佳答案

替换您的点击手势代码,从 swift 3.x 开始,您需要使用 #selector

    let tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(clickToOpen))
self.view.addGestureRecognizer(tapGesture)

关于ios - 获取线程1 : signal sigabrt when trying to use tap gesture recognizer to open url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45302707/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com