UITablewView 在滚动期间停止渲染
简短介绍
目前,我有一个 UITableView,其中填充了自定义单元格,显示当前上传到服务器的文件的上传进度。上传过程只是使用 NSURLConnection 的标准异步方法在后台异步运行的 NSURLConnection 对象。
问题是,在滚动期间,UITableView,或者我认为 UITableview 的 UIScrollView,有点阻塞整个主线程,该主线程执行重要信息,例如我的文件的上传过程等,直到 UIScrollView 处于停滞不前。
研究
现在我确实遇到了我认为与我在这篇文章中完全相同的问题:类似的问题
所以看起来整个主线程确实被阻塞了。我还成功地添加了一个计时器,就像上面的帖子一样,即使在滚动过程中也会被调用。但是......不幸的是它并没有真正解决我的情况。
问题仍然是 NSURLConnection 对象被阻止,这意味着 NSURLConnection 删除方法:didSendBodyData
仍然没有被调用,这是我获取写入服务器的新字节量等的地方,所以我根本无法接收数据。
有什么办法可以解决这个问题吗?我是否必须创建某种自定义 UIScrollView 或类似的东西来绕过限制,例如创建我自己的滚动机制?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过将 NSURLConnection 代码移至后台线程上运行?这应该允许它即使在用户滚动时也能运行。
您的
UITableView
是一个UIScrollView
(您提到的),这意味着您可以针对它注册一个UIScrollViewDelegate
。如果您实现scrollViewDidScroll:
,您可以有效地让主线程轮询以查看是否已从NSURLConnection
获得结果。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 aUIScrollView
(which you mentioned) and that means you can register aUIScrollViewDelegate
against it. If you implementscrollViewDidScroll:
you can effectively have you main thread poll to see if you have the results from yourNSURLConnection
yet.