darksky
darksky

Reputation: 21059

NSURLConnection and Images Download Question

I have a JSON feed with about 350 records. I used NSURLConnection to download them upon launch from the feed. Each item in the feed has a URL to an image. I need download an image thumbnail for many of those feeds. It is very similar to what a twitter client would do (since I also display them in a table view). When I use normal UIImage = [UIImage alloc] initWithData etc... It will take forever. Also, since the table cells load as I scroll, scrolling down while loading the images would cause the app to load the images and terrible user experience (as well as lag).

What are some alternatives that you suggest? I am using NSURLConnection in the application:didFinishLaunch. Should I implement it one more time in the view controller of that table view class?

Any suggestions / guidance is appreciated.

Thank you,

Upvotes: 0

Views: 982

Answers (4)

Felipe Sabino
Felipe Sabino

Reputation: 18225

As you have the images URL, you can use TCWebImageView to download and cache (in the file system) the images on demand.

https://github.com/totocaster/TCWebImageView

which is a nice and simple async image component by the way.

EDIT:

Another good library that is worth taking a look is ASIHTTPRequest's ASINetworkQueue (which is a nice subclass of NSOperationQueue) and it makes it a very easy and robust way of performing a heavy load (350+ items) download management

EDIT 2:

There is another good solution inside the AFNetworking library, which is the AFImageRequestOperation where you can easily use its UIImageView category with no need for subclassing or managing the download queue.

Upvotes: 2

hooleyhoop
hooleyhoop

Reputation: 9198

You say

It is very similar to what a twitter client would do

and

Also, since the table cells load as I scroll, scrolling down while loading the images would cause the app to load the images and terrible user experience (as well as lag).

I have Twitterrific, Twitter and TweetDeck install and this is exactly what they do (ie load images as they become visible when the user scrolls). Obviously each image, if used more than once (as it probably would be in a twitter timeline) would only be downloaded once and cached.

Upvotes: 0

You have to use Async image downloading in order to download images and that will not disturb the flow of other code, while images will download with time. You can take help from http://code.google.com/p/iphone-lib/wiki/AsyncImageView.

Upvotes: 1

zaph
zaph

Reputation: 112873

Users are a lot happier with a fast launch.

I would suggest putting the images in you app, the size will probably be reasonable.

Upvotes: 0

Related Questions