2

the issues is the progress view have maximum value to 1.0 i try to change it for the file size which i download it from the internet but i couldn't please can tell me how can i change the maximum value for the progress view so it is match which the file size which i download it

the code below:

let cell = tableView.dequeueReusableCell(withIdentifier: "DownloadCell", for: indexPath) as? DownloadCell

cell?.progreeView.progress = arrayOfObjects[indexPath.row].totalData

// totalData from object  is file size which i download it from the internet 

thanks a lot

Hamza Hassan
  • 107
  • 1
  • 10

1 Answers1

3

You Don't need to change progress maximum value, you just need to do math to calculate progressView.progress. For Example, lets says that your total data is 500 and your current downloaded data is 328, then 328 / 500 = 0.656 and thats your current progress, so you can do something like: (Creating 2 new variables)

let cell = tableView.dequeueReusableCell(withIdentifier: "DownloadCell", for: indexPath) as? DownloadCell

cell?.progreeView.progress = currentDownloadedData / totalSize
Mago Nicolas Palacios
  • 2,501
  • 1
  • 15
  • 27
  • this give me the current downloading , but i need to set the progress view for the specific size because for example if my file size is 16 MB and my current file size which i downloading is 4 MB and it is increasing the progress view in this status is on half while the half for the progress view is 8 MB ? i hope you understanding me – Hamza Hassan Jan 07 '17 at 21:42
  • That proportion otro increase the progress size is done with the formula I gave you. Maybe post the complete code and I could help you. – Mago Nicolas Palacios Jan 07 '17 at 21:45
  • yes i know my friend but your code is increase the progress view until reach to the end and this is correct but i need set maximum value for the progress view with the total file size for example , while progress view is reach to 1.0 in this situation the progress is full , i need to set the maximum value for progress to 10 MB so when it is reach to 10 mb this is full in this situation – Hamza Hassan Jan 08 '17 at 07:54
  • @HamzaHassan sum sizes of all files into one variable and then as you download files also store total amount downloaded into another variable... then use Mago's formula to calculate current progress of all files together by dividing sumDownloadedData with sumDataToDownload and you got your value between 0 and 1 for the progress bar – budiDino Jan 10 '17 at 02:40