获取线程1:尝试使用点击手势识别器打开网址时发出信号sigabrt

时间:2017-07-25 12:02:41

标签: ios swift xcode url uitapgesturerecognizer

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

  

以NSException(lldb)类型的未捕获异常终止

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

  

[Hello.ViewController clickToOpen]:无法识别的选择器发送到实例。

还有一个

  

线程1:信号SIGABRT

  

class AppDelegate:UIResponder,UIApplicationDelegate {"在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)
    }

}

}

1 个答案:

答案 0 :(得分:0)

替换您的点击手势代码&amp;从swift 3.x开始,您需要使用 fluidPage(width = 12, status = "primary", collapsible = TRUE, solidHeader = TRUE, tags$div(HTML('<script src="//platform.linkedin.com/in.js" type="text/javascript"> </script><script type="IN/CompanyInsider" data-id="2896" data-format="inline" data-width="1"></script'))),

#selector