Manish Agrawal
Manish Agrawal

Reputation: 11037

Show images asynchronouly in UITableView from server in iPhone

When I try to fetch the images in UITableView using NSURL
UIImage image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://mysite.com/mobile/abc.jpg]]];
my application get freezes until the images loaded. Also when I scroll the table it get images from the server again and scroll get stuck for some time.
I know this is happening because of downloading images synchronously from server.
Is there any solution so that I can download the image asynchronously from server and store it locally or in cache so that when table scrolls it did not get images again from server.

Thanks

Upvotes: 0

Views: 1666

Answers (2)

Keller
Keller

Reputation: 17081

Check out EGOImageLoading by enormego. Works just like UIImage (and caches images) but lets you load from HTTP asynchronously.

Upvotes: 2

Suhail Patel
Suhail Patel

Reputation: 13694

You can create your own class which leverages NSURLConnection and it's various Asynchronous methods to load your images in the background and then have a callback to display it in the cell.

However, there are some excellent libraries which do exactly what you've described. HJCache is one i've used and recommend for this sole purpose

Upvotes: 0

Related Questions