swift2 - Passing arguments to #selector method in swift -


this question has answer here:

i want pass multiple argument function while click image. here code

var param1 = 120 var param2 = "hello" var param3 =  "world"  let image: uiimage = uiimage(named: "imagename")!  bgimage = uiimageview(image: image)  let singletap = uitapgesturerecognizer(target: self, action:#selector(welcomeviewcontroller.tapdetected(_:secondparam:thirdparam:))) singletap.numberoftapsrequired = 1 bgimage!.userinteractionenabled = true bgimage!.addgesturerecognizer(singletap) 

calling function

func tapdetected(firstparam: int, secondparam: string, thirdparam: string) { print("single tap on imageview")             print(firstparam)  //print 120             print(secondparam) // print hello             print(thirdparam) /print world         } 

how can pass arguments can correct values?

you can't. documentation:

a gesture recognizer has 1 or more target-action pairs associated it.
...
action methods invoked must conform 1 of following signatures:

- (void)handlegesture; - (void)handlegesture:(uigesturerecognizer *)gesturerecognizer; 

you may use instance variables pass parameters.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -