uitableview - Don't want to hold 3 seconds to invoked didSelectRowAtIndexPath after playing streaming -
i created ios app in swift
custom cell , vlcplayer
. in project, click specific cell , vlcplayer
download video according fileid
in cell.
when vlcplayer
not show streaming, uitableview
works fine, , didselectrowatindexpath
invoked immediately.
my problem is: after vlcplayer
become play streaming, have hold 3 seconds in cell invoke didselectrowatindexpath
, want invoke immediately.
can tell me how deal problem?
here code:
func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { var cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) as! timelinetableviewcell let motionimage:uiimage! motionimage = uiimage (named: "motion.png") if self.items[indexpath.row].image == nil { cell.snapshotimage.image = uiimage(named: "loading_page.png") } else { cell.snapshotimage.image = self.items[indexpath.row].image } cell.motionimage.image = motionimage cell.daylabel.text = self.items[indexpath.row].text cell.timelabel.text = self.items[indexpath.row].date //update cell image if self.items[indexpath.row].image == nil { dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0)){ //1. trying image cache var image: anyobject? = timelineimagecache.objectforkey(userdefaults.stringforkey("cameraname")! + self.items[indexpath.row].fileid! + fileidentifer) //2. trying image filesystem let path = nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true)[0] as! string let folderpath = path.stringbyappendingpathcomponent("timelineimage/") let destinationpath = folderpath.stringbyappendingpathcomponent(userdefaults.stringforkey("cameraname")! + self.items[indexpath.row].fileid! + fileidentifer + ".jpg") var filemanager = nsfilemanager.defaultmanager() if image == nil { if (filemanager.fileexistsatpath(destinationpath)) { image = uiimage(contentsoffile: destinationpath) println("file system") } } //3. if there's no cache , not exist in file system, download if image == nil { image = webstorageconnection.getvideosnapshot(self.items[indexpath.row].fileid!) //imagecache[timeframe.fileid!] = image timelineimagecache.setobject(image!, forkey: userdefaults.stringforkey("cameraname")! + self.items[indexpath.row].fileid! + fileidentifer) filesystemmanager.instance.saveimagetoloacl(image as! uiimage, filename: userdefaults.stringforkey("cameraname")! + self.items[indexpath.row].fileid! + fileidentifer) println("done download") } dispatch_async(dispatch_get_main_queue()){ cell.snapshotimage.image = image as? uiimage //println("ui") } } } return cell } func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { println("you selected cell #\(indexpath.row)!") let url = webstorageconnection.getdirectdownloadurl(fileid: items[indexpath.row].fileid!) vlcplayer.stop() vlcloadingindicator.startanimating() let media : vlcmedia = vlcmedia(url: url) vlcmedia vlcplayer.media = media vlcplayer.play() }
thanks everyone!
you want disabled didselectrowatindexpath
3 sec. after playing. correct?
var isallowed = bool() // default true func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { println("you selected cell #\(indexpath.row)!") let url = webstorageconnection.getdirectdownloadurl(fileid: items[indexpath.row].fileid!) vlcplayer.stop() vlcloadingindicator.startanimating() let media : vlcmedia = vlcmedia(url: url) vlcmedia vlcplayer.media = media vlcplayer.play() isallowed = false dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0)){ nsthread.sleepfortimeinterval(3) // sleeps 3 sec. dispatch_async(dispatch_get_main_queue()){ isallowed = true } } }
or use timer
var isallowed = bool() // default true func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { println("you selected cell #\(indexpath.row)!") let url = webstorageconnection.getdirectdownloadurl(fileid: items[indexpath.row].fileid!) vlcplayer.stop() vlcloadingindicator.startanimating() let media : vlcmedia = vlcmedia(url: url) vlcmedia vlcplayer.media = media vlcplayer.play() isallowed = false var timer = nstimer.scheduledtimerwithtimeinterval(3, target: self, selector: selector("yourselector"), userinfo: nil, repeats: false) } func yourselector() { isallowed = true }
this magic , not allow user selecting cell @ indexpath... under
func tableview(tableview: uitableview, willselectrowatindexpath indexpath: nsindexpath) -> nsindexpath? { //return nil if dont want allow selection if (isallowed == false) { return nil } return indexpath }
Comments
Post a Comment