how to get images from server efficently in table view - iphone

I am having 5000 images as thumbnails of videos and it has to be shown in the table view, what is the best way of done it?? Please help me.

You can use the Lazy Loading concept, take a look at the apple sample code for demonstrate a lazy loading UITableView.
Update
This is in case of using a server side for hosting the images (which is a best solution for your app cause it's wrong to save a huge number of images (5000 image) in the app.

Related

How to create an application which uses bulk of images from web service

I am newly in iOS development.I have to make an application for a car dealer in which i have to show different cars with different colors.Please tell me the best way because i have to fetch lots of images every time from the web server.How can i reduce the rendering time in fetching the images.
Please consider i am very new in ios development and need your help.
If you have any sample application please share it with me.
You can use DB to store images as BLOB and also fetch images only when there is update at server.
First, make sure you send images that are no larger than needed.
If you have a list view that shows pictures of the cars, have a webservice send you premade thumbnails that are (preferably) exactly the right size.
Second, Make sure the images are loaded separately from the data set.
The best place to do this, would be in the controllers for your UITableViewCell.
Just have your UITableViewCell start their own thread to download and display the image as soon as they come into view.
Third; caching.
Make sure you save local copies of the thumbnails, and make sure the Table View Cells search for local copies of the images, and load those instead of downloading them if they are already locally present.
you can do:-
use lazy loading
use paging
use predicates for searches
use fast enumeration
these things in general will keep your app smooth
If you are going to show images in UITableView then you can use lazy loading. It will load images only for the displayed rows and once image for any row index has been downloaded, it will not repeat downloading for that row index. So its faster and useful.

What's the Best way for Lazy loading images in iPhone?

I want to know, what is the best way for lazy loading. For me, most of the applications i have used parsing and get the url from the server and put the image into the table view. So i have implemented lazy loading for improving the performance of the application. Now i want to know the best method for lazy loading images. Because i have used lazy loading into the four ways,
Lazy loading images from Apple developer.com
Implemented Asynchronous method for improving the lazy loading
Used separate main thread for handling the image downloaded.
Have used ECOImageLoadingDemo application for lazy loading.
But i have used the above four methods to achieve the lazy loading. But i want to know what's the best method for lazy loading. Which one is best for performance wise and memory wise is suitable for that?
Thanks in Advance.
Regards,
Pugal
From my experience, performance-wise and memory-wise solutions are on the opposite ends of a slider. You can move around with your solution somewhere between these two, but with the disadvantage that having the best solution performance-wise, usually means a worse solution memory-wise and vice-versa. I hope I explained this clear enough :)
Here's how I handle the problem of lazy loading images:
In my application I created ONE entity which I called GlobalImageProvider. All requests for images go through this entity. This way I have control on how many threads I use to download and I can implement a caching system (memory + local disk), all of these completely transparent to the application and with full control.
By controlling the size of the cache, I can control how quick the application feels. Performance wise, nothing compares with having an UIImage already created in memory.
Memory-wise, you can even choose to disable the cache.
Even more, I can even change the number of threads dynamically while the application is running depending on the quality of the network I have.
To make the online requests, I'm using NSURLConnection but I plan on switching to something else since I've read that it leaks memory.
On the view&controllers side, I have a AsyncImageView which is just a UIImageView that knows how to work with the GlobalImageProvider. It knows to display an activity indicator while loading and can handle the response from GlobalImageProvider.
If you know the URL of the image you want, all you need to do is add a AsyncImageView to your screen and make a request to the GlobalImageProvider with the AsyncImageView as the "handler" for that image.
If you don't like mixing data with the image views, you can add a ViewController between the GlobalImageProvider and AsyncImageView. He gets the image response and puts it in the ImageView.
That's about it, hope it helps you a bit.
You can take a look at this excellent tutorial from Peepcode in the section Bonus: KVO for Cell Images
http://peepcode.com/products/iphone-view-controllers-part-ii

Loading PDFs or Images from URL into a CoverFlow view

I want to load PDFs or Images into a View, but when the source is an URL there might be connection lags, so I wonder what is the best approach when loading content (like magazines) into a Coverflow view in the iPhone?.
(For Coverflow, something like this: http://apparentlogic.com/openflow/ )
Is it ok to get a pdf file then
obtain corresponding page images and
show them in an appropriate
resolution a Coverflow view?
(Downloading the hole PDF might take
long)
Or is better to download images as
needed and then pass them to the
Coverflow? (Although resolution
might be a problem, hence maybe I
wil need more than one image per
page)
Would it be better to have a pdf
file for every page?(So they can be
rendered at any resolution and I
don't have to download the hole file
at once)
I hope you can give some advices on this.
Thanks in advance.
Just for the record:
After some research I came up with images approach. They are the simpler, fastest, and reasonable good resolution. They can be loaded in 2 stages, regular resolution and better resolution for zooming, etc.

How to preload or lazyload images in a UITableView on iPhone?

I'm having a problem when scrolling down and up a tableView on iPhone it gets kind of stuck while loading the images i need a method to preload the images so the scroll can be fluid or load the images 'till the scroll event stops...
any help on this?
I found this article very helpful. It provides a very detailed example for lazy loading of images in the main runloop.
Lazy Table Images Sample Code included in iPhone Developer Resources. Check out Photo Locations Sample Code as well. It uses Core Data and "lazy loading" techniques if your image files are stored on the device.
Well, generally speaking, preloading images for table view is a bad idea. Think of a following situation: you have 100 cells, each containing one image. That means you'll have to load 100 images before showing the table, which will have a serious impact on avaliable memory.
The "loading effect" you're talking about can be caused by two things:
a) as you have said, the problem with loading images. If so, do it in another thread, and pass the image to main thread when it loads
b) You're using images that are bigger or smaller than the given size. This will result in resizing the image when it appears on screen, causing the ugly stop-effect - the solution is to draw images in size which is exactly the same as their size.
Chope this was helpful, Paul
Not sure about images, but with text I have downloaded JSON files when the view loads, parsed into an array and then loaded the tableview with that array.

Lazy load images in UITableViewCell

I have some 50 custom cells in my UITableView. I want to display an image and a label in the cells where I get the images from URLs.
I want to do a lazy load of images so the UI does not freeze up while the images are being loaded. I tried getting the images in separate threads but I have to load each image every time a cell becomes visible again (Otherwise reuse of cells shows old images)
Apps like Facebook load images only for cells currently visible and once the images are loaded, they are not loaded again. Can someone please tell me how to duplicate this behavior.
Thanks.
Edit
Trying to cache images in an NSMutableDictionary object creates problems when the user scrolls fast. I am getting images only when scrolling completely stops and clearing out the cache on memory warning. But the app invariably gets a memory warning (due to size of images being cached) and clears the cache before reloading. If scrolling is very fast, it crashes.
Any other suggestions are welcome
Loading the images on a background thread is still a good idea. If you didn't want to reload them each time, I'd suggest setting up an NSMutableDictionary and storing the images in there. You could use some unique identifier, like the row ID or even the name of the image, as the key for each image.
When loading a cell, you'd send an objectForKey: message to the NSMutableDictionary to retrieve the image for that particular cell (based on your unique key for it). If it returns nil, that means that the image is missing from the cache and you need your background image loading thread to go retrieve it. Otherwise, you will get back the appropriate image for your table cell to display. On a memory warning, you could clear out this cache of images with no adverse effects (aside from forcing them to be reloaded again on demand).
I have just successfully tackled the same problem by using a custom NSOperation to load the images in a queing fasion and stored them into a static NSMutableDictionary as a cache. Below is a link to the basis of the code I used to solve the problem.
Loading remote images for UITableViewCell
Best to read all the threads in the forum to help you understand what's actually going on.
lostInTransit,
I am having a similar problem and while exploring the many different possible solutions I found this blog post:
davidgolightly.blogspot.com/2009/02/asynchronous-image-caching-with-iphone.html
I would also suggest that you download the URLCache sample from the apple developer website:
developer.apple.com/iphone/prerelease/library/samplecode/URLCache/
And here is another post on the problem:
www.markj.net/iphone-asynchronous-table-image/
I'd love you to share your findings as well.
Lazy loading is like synchronous type request.. means wait for respond
ego image button is solution for that..
ego image button is asynchronous type request..don't wait for respond..just display data at a time....
you can download folder from github....
add to your project...
in xib..at image view ,change class to ego image button...
make object of it in m file...
you can use.....
For those who are interested, and are lazy like me, I would like to suggest an open source (MIT license) implementation of lazy/cached network of UIImageView images: SDWebImage
UITableView with image caching and resizing/setting in background thread:
http://blog.slaunchaman.com/2011/08/12/gcd-example-updated-now-with-more-speed/
This is Tutorial about NSOperation with example that show how to Lazy load images in UITableViewCell