UITablewView stops renderings during scrolling

社会主义新天地 提交于 2019-12-14 02:22:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!