swift - Swift3 iOS - How to make UITapGestureRecognizer trigger function -
i trying add uitapgesture
uibutton trigger function when tapped. using swift 3
, getting error:
terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[swiftrunner.viewcontroller tapblurbutton]: unrecognized selector sent instance 0x149e07610'
this have:
// swift 3 import uikit class viewcontroller { @iboutlet weak var qsblurbutton: uibutton! override func viewdidload() { super.viewdidload() let tapgesture = uitapgesturerecognizer(target: self, action: selector(("tapblurbutton"))) qsblurbutton.addgesturerecognizer(tapgesture) } func tapblurbutton(sender: uitapgesturerecognizer) { print("please help!") } }
from code using swift 3.0 change selector
syntax
let tapgesture = uitapgesturerecognizer(target: self, action: #selector(self.tapblurbutton(_:)))
and function this
func tapblurbutton(_ sender: uitapgesturerecognizer) { print("please help!") }
edit:
not idea using button tap gesture, instead of use inbuilt method addtarget
button no need create tap gesture this
qsblurbutton.addtarget(self, action: #selector(self.tapblurbutton(_:)), forcontrolevents: .touchupinside) func tapblurbutton(_ sender: uibutton) { print("please help!") }
Comments
Post a Comment