ios - Passing arguments to selector in Swift3 -


i'm programmatically adding uitapgesturerecognizer 1 of views:

let gesture = uitapgesturerecognizer(target: self, action: #selector(self.handletap(modelobj:mymodelobj)))  self.imageview.addgesturerecognizer(gesture)  func handletap(modelobj: model) {   // doing stuff model object here } 

the first problem encountered "argument of '#selector' not refer '@objc' method, property, or initializer.

cool, added @objc handletap signature:

@objc func handletap(modelobj: model) {   // doing stuff model object here } 

now i'm getting error "method cannot marked @objc because type of parameter cannot represented in objective-c.

it's image of map of building, pin images indicating location of points of interest. when user taps 1 of these pins i'd know point of interest tapped, , have model object describes these points of interest. use model object give pin image it's coordinates on map thought have been easy me send object gesture handler.

it looks you're misunderstanding couple of things.

when using target/action, function signature has have form…

func dosomething(sender: any) 

or

func dosomething(sender: any, forevent event: uievent) 

where…

the sender parameter control object sending action message.

in case, sender uitapgesturerecognizer

also, #selector() should contain func signature, , not include passed parameters. for…

func handletap(sender: uigesturerecognizer) {  } 

you should have…

let gesture = uitapgesturerecognizer(target: self, action: #selector(handletap(sender:))) 

assuming func , gesture within view controller, of modelobj property / ivar, there's no need pass gesture recogniser, can refer in handletap


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -