ios - Getting thread 1: signal sigabrt when trying to use tap gesture recognizer to open url -


i trying use tap gesture recognizer open url when tapping image. code builds when try tap image, terminates , displays

terminating uncaught exception of type nsexception (lldb)

in console. console displays

[hello.viewcontroller clicktoopen]: unrecognized selector sent instance.

and there

thread 1: signal sigabrt

in line

class appdelegate: uiresponder, uiapplicationdelegate {" in appdelegate.swift.

the viewcontroller code below:

// //  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 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 url)     }  }  } 

replace tap gesture code & swift 3.x need use #selector

    let tapgesture = uitapgesturerecognizer.init(target: self, action: #selector(clicktoopen))     self.view.addgesturerecognizer(tapgesture) 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -