Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

iphone - Delayed UIImageView Rendering in UITableView

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.

-- UPDATE --

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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];

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...