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 渲染
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01