Delayed UIImageView Rendering in UITableView(UITableView 中的延迟 UIImageView 渲染)
问题描述
好的,我有一个带有自定义 UITableViewCell 的
.所有非常标准的东西......UITableView
,每个都包含一个 UIImageView
,其图像通过 <代码>NSURLConnection
Ok, I've got a UITableView
with custom UITableViewCell
s that each contain a UIImageView
whose images are being downloaded asynchronously via an NSURLConnection
. All pretty standard stuff...
问题是,当表格滚动时,新图像会在后台正确下载,但在表格停止移动之前不会渲染.
The issue is, when the table scrolls, the new images are downloaded in the background correctly but not RENDERED until the table stops moving.
如何让表格即使在移动时也能呈现其内容?谢谢.
How do I get the table to render it's content even when it's moving? Thanks.
-- 更新--
仔细观察后,我发现 NSURLConnection
委托方法在表格停止滚动之前不会触发.不知道为什么.任何帮助都会很棒.
After a closer look, I'm finding that the NSURLConnection
delegate methods aren't firing until the table stops scrolling. Not sure why. Any help would be great.
推荐答案
在您停止滚动之前连接委托消息不会触发的原因是因为在滚动期间,运行循环处于 UITrackingRunLoopMode
.默认情况下,NSURLConnection
仅在 NSDefaultRunLoopMode
中进行调度,因此您在滚动时不会收到任何消息.
The reason the connection delegate messages aren't firing until you stop scrolling is because during scrolling, the run loop is in UITrackingRunLoopMode
. By default, NSURLConnection
schedules itself in NSDefaultRunLoopMode
only, so you don't get any messages while scrolling.
以下是在普通"模式下安排连接的方法,其中包括 UITrackingRunLoopMode
:
Here's how to schedule the connection in the "common" modes, which includes UITrackingRunLoopMode
:
NSURLRequest *request = ...
NSURLConnection *connection = [[NSURLConnection alloc]
initWithRequest:request
delegate:self
startImmediately:NO];
[connection scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSRunLoopCommonModes];
[connection start];
请注意,您必须在初始化程序中指定 startImmediately:NO
,这似乎与 Apple 的文档背道而驰,该文档建议您即使在启动后也可以更改运行循环模式.
Note that you have to specify startImmediately:NO
in the initializer, which seems to run counter to Apple's documentation that suggests you can change run loop modes even after it has started.
这篇关于UITableView 中的延迟 UIImageView 渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITableView 中的延迟 UIImageView 渲染
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01