ios - How to update a slider on a bunch of table cells continuously? -


the first method tried caused error due disrupting layout, here issue: in have tableview cells have sliders/progress views. value on these sliders needs equal attached item (i assign rss items each cell, music)'s percent has downloaded, if user tapped download it.

i calling func in observer download progress here:

//download progress     func urlsession(_ session: urlsession, downloadtask: urlsessiondownloadtask, didwritedata byteswritten: int64, totalbyteswritten: int64, totalbytesexpectedtowrite: int64) {         let progress = double(totalbyteswritten) / double(totalbytesexpectedtowrite)         print("\(downloadtask.originalrequest!.url!.absolutestring) \(progress)")          updatelistcells()     } 

here how try update cells user see progress bar gradually growing - have subclassed cells:

func updatelistcells() {     if let table = listvc.mytableview {         if(!table.visiblecells.isempty)         {             v in table.visiblecells {                 let cell = v as! rsstableviewcell                 cell.updateloader()             }         }     } }  func updateloader()     {         self.bringsubview(tofront: downloadloader)         if(pathurl != nil)         {             if(checkifexists(url: pathurl!))             {                 downloadloader.progress = 1             }             else {                 d in downloadmanager.operations {                     if(url(string: rssitem.link) == d.value.task.originalrequest?.url)                     {                         let progress = double(d.value.task.countofbytesreceived) / double(d.value.task.countofbytesexpectedtoreceive)                         //print("match: ", d.value.task.countofbytessent)                         downloadloader.progress = float(progress)                     }                 }             }         }         else {             downloadloader.progress = 0         }     } 

but doesn't work continuously. if refresh tableview slider assume current download value.

how can update tableview cells continuously if download happening?

you should run updatelistcells() in main thread (as @arvidurs wrote):

func urlsession(_ session: urlsession, downloadtask: urlsessiondownloadtask, didwritedata byteswritten: int64, totalbyteswritten: int64, totalbytesexpectedtowrite: int64) {     let progress = double(totalbyteswritten) / double(totalbytesexpectedtowrite)     print("\(downloadtask.originalrequest!.url!.absolutestring) \(progress)")     dispatchqueue.main.async {         self.updatelistcells()     } } 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -