ios - pass argument in selector for scheduleTimerwithTimeInterval -


in swift, have uitableviewcell has double tap , single tap implemented. double tap works. however, having bit of trouble single tap. due present of double tap, implemented single tap timer. following code prints out "single tapped"

func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {      var = nsdate().timeintervalsince1970      if (now - lastclick < 0.3) && indexpath.isequal(lastindexpath) {         // double tapped on cell         if let cell = discovertableview.cellforrowatindexpath(indexpath) as? commentcell {             cell.doubletapcellactive({ (addbumpstatus, success) in             })         }         singletaptimer?.invalidate()      } else {         singletaptimer = nstimer.scheduledtimerwithtimeinterval(0.31, target: self, selector: #selector(discovervc.singletapped), userinfo: nil, repeats: false)     }     lastclick =     lastindexpath = indexpath }  func singletapped() {     print("single tapped") } 

however, problem is, want single tap know index path selected. tried doing

#selector(discovervc.singletapped(_:indexpath)) func singletapped(indexpath: nsindexpath) {} 

but gives me error selector not syntax. there way make selector work or better way of doing it?

thanks,

the usual way implement action nstimer parameter

func singletapped(timer : nstimer) {    print("single tapped", timer.userinfo!["indexpath"] as! nsindexpath) } 

and pass custom data via userinfo property of timer example

singletaptimer = nstimer.scheduledtimerwithtimeinterval(0.31,                           target: self,                           selector: #selector(singletapped(_:)),                           userinfo: ["indexpath":indexpath],                           repeats: false) 

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 -