问题
Short Intro
Currently I have a UITableView which is filled with custom cells that displays uploading progress for files currently being uploaded to a server. The uploading processes are simply NSURLConnection objects running asynchronously in the background using the standard asynchronous method of the NSURLConnection.
The problem is that during scrolling, the UITableView, or I suppose the UIScrollView of the UITableview, kind of blocks the entire main thread, which does that vital information such as the uploading process of my files and such are not updated until the UIScrollView is at a standstill.
Research
Now I did bump into I think what is the exact same issue as mine in this post: Similar Question
So it does seem that the entire main thread gets blocked. I also successfully got to add a timer like in the above post, which does get called even during scrolling. But... it unfortunately does not really solve my situation.
The problem is still that the NSURLConnection objects gets blocked, which means that the NSURLConnection deletage method: didSendBodyData
still does not get called, which is where I get the new amount of bytes written to the server and so forth, so I simply can't receive the data.
Is there any way around this problem? Would I have to create some kind of custom UIScrollView or something like that to get around the limitation, like creating my own scrolling mechanism?
回答1:
Have you considered moving the NSURLConnection
code to run on a background thread? This should allow it to run even when the user scrolls.
Your UITableView
is a UIScrollView
(which you mentioned) and that means you can register a UIScrollViewDelegate
against it. If you implement scrollViewDidScroll:
you can effectively have you main thread poll to see if you have the results from your NSURLConnection
yet.
来源:https://stackoverflow.com/questions/9328073/uitablewview-stops-renderings-during-scrolling