Delayed UIImageView Rendering in UITableView(UITableView 中的延迟 UIImageView 渲染)
问题描述
好的,我有一个带有自定义 UITableViewCell 的 .所有非常标准的东西......UITableView,每个都包含一个 UIImageView,其图像通过 <代码>NSURLConnection
Ok, I've got a UITableView with custom UITableViewCells 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 渲染
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
