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
Post a Comment