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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -