Reputation: 10779
How do I go about loading images from my website into UITableView? What is the best way for performance? And how would one handle rerendering the images as the table cells get reused?
And how can I pass the image from the tableView to the cell during didSelect..Row method?
Upvotes: 3
Views: 2576
Reputation: 7767
The best way for performance is to do lazy loading. You Shouldn't download an image the user is not viewing. A sample code is available at he below link
It may look a bit complicated at first, but actually it is not. If you are not sure how to modify your tableview for this code, modify this codes's rootview controller for your need. Eg: Load a custom cell from nib
PS: You have to pass the image link in xml to use this code
Upvotes: 2
Reputation: 7200
Take the number of pixels all the images will have together (ideally you can make small perfectly sized images on your web site?) and then multiply by 4. That's how many bytes you are dealing with. For your users sake, keep it low!
Download the images in NSOperations synchronously (although apple docs have much more complicated solutions), into an NSMutableDictionary, with key being the url, and the png or jpeg data (or the actual UIImage) as the value. You need to use @synchronize() around all access to the cached dictionary, as you will be accessing the array from several threads.
When you get a memory warning, just tell the dictionary to remove all items. (inside a sync block)
-(void)somememorywarning;
{
@synchronized(gImageCacheDict)
{
[gImageCacheDict removeAllObjects];
}
}
I leave the table cell stuff to the docs, etc but you don't do it the didSelect call..
Upvotes: 0