UITablewView 在滚动期间停止渲染

发布于 2025-01-07 03:13:50 字数 630 浏览 8 评论 0原文

简短介绍

目前,我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猛虎独行 2025-01-14 03:13:50

您是否考虑过将 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文