UITablewView 在滚动期间停止渲染 [英] UITablewView stops renderings during scrolling

查看:45
本文介绍了UITablewView 在滚动期间停止渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短介绍

目前我有一个 UITableView,它充满了自定义单元格,显示当前正在上传到服务器的文件的上传进度.上传过程只是使用 NSURLConnection 的标准异步方法在后台异步运行的 NSURLConnection 对象.

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.

问题是在滚动过程中,UITableView 或者我想 UITableview 的 UIScrollView 会阻塞整个主线程,它会执行诸如我的文件的上传过程之类的重要信息,直到UIScrollView 处于停滞状态.

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.

研究

现在我确实在这篇文章中遇到了与我完全相同的问题:类似问题

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.

问题仍然是NSURLConnection对象被阻塞了,这意味着NSURLConnection删除方法:didSendBodyData

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.

有什么办法可以解决这个问题吗?我是否必须创建某种自定义 UIScrollView 或类似的东西来绕过限制,比如创建我自己的滚动机制?

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?

推荐答案

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

你的 UITableView 是一个 UIScrollView(你提到的),这意味着你可以针对它注册一个 UIScrollViewDelegate .如果你实现了 scrollViewDidScroll: 你可以有效地让你的主线程轮询看看你是否有来自 NSURLConnection 的结果.

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.

这篇关于UITablewView 在滚动期间停止渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆