Illep
Illep

Reputation: 16841

Adding image to Tableview

I am using SDWebImage to populate my Tableview with Images (downloaded and displayed).

What i did was i included the library in my project, then added the nessasry frameworks as mentioned in its GitHub project website.

Then i added #import "UIImageView+WebCache.h" the import, and the delegate SDWebImageManagerDelegate

In the cellForRowAtIndexPath method, i added the following;

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

 if (cell == nil) {
 cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

 [cell.animalImageView  setImageWithURL: [NSURL URLWithString:animal.imageURL]
                                        placeholderImage:[UIImage imageNamed:@"imagenotfound.png"]];

}

I presume this does everything as described in its project website

An UIImageView category adding web image and cache management to the Cocoa Touch framework An asynchronous image downloader An asynchronous memory + disk image caching with automatic cache expiration handling A guarantee that the same URL won't be downloaded several times A guarantee that bogus URLs won't be retried again and again Performances!

But, when i run the application in on my phone, the scrolling is slow. then when i scroll up and down for awhile, it almost gets stuck (but it still scrolls).

Can someone please go through my code, and tell me what i have missed. I have been stuck with this issue for days. Help

}

Upvotes: 0

Views: 110

Answers (3)

oriolpons
oriolpons

Reputation: 1883

Also you can try to declare an NSMutableArray and store the UIImage there, so you don't have to download them twice when you scroll

Upvotes: 0

Janak Nirmal
Janak Nirmal

Reputation: 22726

You should put assigning image statement outside of that checking nil condition as

if (cell == nil) 
{
 cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

[cell.animalImageView  setImageWithURL: [NSURL URLWithString:animal.imageURL]
                                        placeholderImage:[UIImage imageNamed:@"imagenotfound.png"]];

Upvotes: 1

elprl
elprl

Reputation: 1960

Here are my thoughts: Are you using the [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; method or are you creating a new cell for each row? The cell isn't autoreleased. How big are the images and the default image?

Upvotes: 1

Related Questions