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
Post a Comment