开发者

question on displaying UIProgressView in each table cell

I'm trying to upload a few files to a server. The files are listed on the UItableview. My question is:

What should i do to display UIProgressView in each table cell and show the progress of each file being uploaded.

My current code is able to show the UIProgressView in each cell but when i try to upload, the progress bar did not move. The program is suppose to upload 1 file at a time which after the first file is completed, the second will start to upload. In response, when the first file is开发者_StackOverflow中文版 done, the progress bar of the first file will stop and the progress bar for the secong file will start to move. Hope this is clear. I really need some help on this and i can't find it on the web.Thanks in advance. Thanks


You will have to maintain the progress value of each cell in an array.

I guess you must be setting the progress value of UIProgressView object at cellForRowAtIndexPath method, so you need to call [self.tableView reloadData] whenever you get callback from you network code which is uploading file to server with current upload size...


Possible solution (could be optimized): (Sorry for the formatting, could not get it working)

  • Create UIProgressView for each cell in your tableView

  • Create a field in your view controller, where you will store number of bytes already uploaded (bytesAlreadyUploaded) - you should repeatidly receive such info from your uploader.

  • Create a field where you will store number of bytes to be uploaded for the current upload (bytesToUpload)

  • Create a field where you will assign pointer to the progress view currently used (progressViewCurrentlyUsed)

  • Create a method in which you will refresh your progress:
  • (void) refreshProgress { progressViewCurrentlyUsed.progress = bytesAlreadyUploaded / (CGFloat)bytesToUpload;
    }
  • Create a NSTimer, which will call this refreshProgress method several times a second:

refreshTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(refreshProgress) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:refreshTimer forMode:NSDefaultRunLoopMode];

  • When you change the file being uploaded, change progressViewCurrentlyUsed, bytesToUpload and zero bytesAlreadyUploaded
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜