当我运行我的代码时,这个错误总是发生。您能告诉我问题出在哪里以及如何在 Swift 3 中修复它吗?
错误:
[UIWebView tapAction:]: unrecognized selector sent to instance 0x7f9bfbf14e60
代码:
class ViewController: UIViewController, UITextFieldDelegate, UIGestureRecognizerDelegate {
@IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = URL(string: "http://www.pdf995.com/samples/pdf.pdf")!
webView.loadRequest(URLRequest(url: url))
let webViewTapped = UITapGestureRecognizer(target: webView, action: #selector(self.tapAction(_:)))
webViewTapped.numberOfTouchesRequired = 1
webViewTapped.delegate = self
webView.addGestureRecognizer(webViewTapped)
}
func tapAction(_ sender: UITapGestureRecognizer) {
let point = sender.location(in: self.view)
print("123")
print(point.x)
print(point.y)
}
最佳答案
从 webView
更改目标:
let webViewTapped = UITapGestureRecognizer(target: webView, action: #selector(self.tapAction(_:)))
致自己
:
let webViewTapped = UITapGestureRecognizer(target: self, action: #selector(self.tapAction(_:)))
关于ios - WebView 与触摸事件 UITapGestureRecognizer 无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45055286/