在UITableView中延迟UIImageView渲染 [英] Delayed UIImageView Rendering in UITableView

查看:105
本文介绍了在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:否在初始化程序中,这似乎与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渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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