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

查看:15
本文介绍了UITableView 中的延迟 UIImageView 渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个带有自定义 UITableViewCellUITableView,每个都包含一个 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 渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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