Load more images in UITableView with images using lazy loading - iphone

I have a UITableView with images like photo album, images are loading with lazy loading. I want to load more images while scrolling to the bottom of the tableview or when the last row of the table view reached. How can I do this?

UITableView already does lazy loading for you. It will only ask for the visible cells. If you are taking about adding more images to the table while the user is scrolling, you can implement UIScrollViewDelegate methods to calculate the current scrolling position, and when the user reaches certain point, add more images to the NSMutableArray on your datasource.

Check this
http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
and this Lazy load images in UITableView

You can use SDWebImage.
This library provides a category for UIImageVIew with support for remote images coming from the web.
It provides:
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!

Related

How to load images in UIScrollView asynchronously?

HI,
I am getting my images using JSON and I need to display image at a time when my app is running so please tell me how to use asynchronous method to load the images into the UIScrollView?
Thanks.
whether you use a UITableView or a UIScrollView, you will use the same pattern, its just that you have a bit more plumbing to do with the UIScrollView. I would say use the UITableView unless you want to roll your own multi-column image thumbnail picker.
With the UIScrollView, you will need to create your own virtual rows and columns and detect when the ScrollView has scrolled a new row or a new column into view. You will need to queue (remove) the images that have scrolled out of view, and then load the images that have come into view. All in all, this is not trivial code.
The UITableView does all this for you (rows only, no concept of columns)
Having said that.. here is a reference to using the NSOperation class to lazy load your images into a UITableView while giving the user a smooth experience..
UIImage in uitableViewcell slowdowns scrolling table

UITableView got slowly when dragging

I am new to iPhone development, and I can not understand the working principle of UITableView well.
I customize the UITableViewCell, and the cell contains imageview. In addition, I initialize the cell reusable. However, when I drag the UITableView, it scrolls slowly.
Then what should I do to process it?
If you are loading images from your applications bundle you can increase the scroll speed by making the images the exact size they need to be to fit in the UITableViewCell imageView so the device doesn't have to size them on the fly. Do this by adding smaller versions of the images in your applications bundle, or by resizing them in code as needed in a background thread.
Alternatively if this solution won't work for you, or you are loading images from the internet have a look at Lazy loading images in UITableView, a process where images are only loaded when needed and can be downloaded asynchronously.
Alternatively, you can use a prebuilt class to do your image downloading, caching and lazy loading for you like TTImageView or SDWebImage.

Cocoa-Touch: Is there any open-source UIImageView subclass that supports touchUpInside and initWithUrl?

It's been more than 3 years since Cocoa-Touch is out, the licensing is permissive now.
Many, many apps have UIImageViews that are actually buttons, and load from the internet.
Is there any open UIImageView subclass (or similar) that supports:
adding a target for the touchUpInside event (maybe others too)
initializing with a NSURL, loading the image from that URL (async ofc) and displaying a UIProgressIndicatorView while loading
Or is everyone pretty much rolling their own for this?
It seems to be such a common thing, yet google has no good hits.
You wouldn't want the UIImageView derived class to load its image--especially if it's in a table view because when the user scrolls the table view, the image that will display in the image view would need to change. If you are assigning a specific image to a specific image view within a table view, you run the risk that the image displaying will be out of date by time the image data has actually returned.
While I wouldn't call it trivial as Daniel said, I would say that it is simple enough that you could probably code it up fairly quickly. The idea though is that you want to have some other class, a singleton perhaps, that handles all of your image download requests and then notifies your view that contains your image view that the images are available when the requests complete.
You should also consider that you can set an image for a UIButton, so then you wouldn't need to derive your own UIImageView if all you need is -touchUpInside. You could create an action for the button and implement it pretty easily.

Displaying images in UIScrollView programmatically

I am displaying 200 thumb nail images of size 4kb to 12kb in UIScrollView programmatically by adding UIButton when i am debugging in device it takes time to load the view.. can there is some method to load quickly the thumb mages are store in disk.
Use lazy loading by only loading the ones you show at once in any given moment - or use a background thread to perform the loading while keeping the interface responsive.
If your layout allows, use a table view and a custom cell that holds several thumbnails. That way you can use the tableview controller's built in methods to manage the lazy loading. I'm pretty sure that is how Apple does the thumbnails in the photo library.

How to implement UIImageView-like delayed loading in UITableView

Background:
I have a UITableView showing an image in each cell. These images are all part of a big pdf-file. So what I am doing is actually rendering little pdf-parts in those UITableViewCells, each cell displaying just one piece. Therefore I add a UIView to the contentview of the cell and render the view on demand.
Rendering these pdf-parts is expensive and each takes about 0.2 seconds (only drawing the Pdf-part), which slows the scrolling of the table terrible down.
Idea:
Now, I know there may be a solution when I look how UIImage renders URL-based images. If you create a UIImage based on a url, these images are rendered somehow delayed. E.g have a look at the iTunes-App.
Smooth scrolling is possible, each image is displayed unrendered and after rendering is finished it appears smoothly.
Problem: How can I render an expensive rendering in a UITableViewCell like described above, by somehow showing the cell delayed? Has anybody an idea, how Apple solved it within UIImageView?
Thanks in advance
Daniel
this is (mostly) duplicate of Lazy load images in UITableViewCell. Check the links and examples there.
In short, what you need is spawning a separate thread for loading the PDF thumbnails, and that thread then signaling back to the main thread with the generated images. This is easily done by using performSelectorInBackground:withObject: and performSelectorOnMainThread:withObject:waitUntilDone: methods.