Add some example about using downloader and image cache store components independently + general doc enhancement

This commit is contained in:
Olivier Poitrey 2009-09-21 04:29:00 +02:00
parent 16431cb655
commit 891b957ba8
1 changed files with 38 additions and 6 deletions

View File

@ -4,18 +4,50 @@ Dailymotion Web Image
This library provides a drop-in remplacement for UIImageVIew with support for remote images coming from the web.
It provides:
- Asynchronous image downloader
- Drop-in replacement to UIImageView
- Memory + disk image caching
- Uses NSOperation to perform parallel downloads and caching
- Handles cache expiration transparently
- Asynchronous image downloader
- Asynchronous memory + disk image caching with automatic cache expiration handling
How To Use It
-------------
Most common use is in conjunction with an UITableView. Just place an UIImageView in you UITableViewCell in interface builder, and set its class to DMImageView in the identity panel. Then, in tableView:cellForRowAtIndexPath:, you just have to send a setImageWithURL: to the DMWebImage view with the URL of the image.
### DMWebImageView as UIImageWeb Drop-In Replacement
If in interface builder, an image was configured in the UIImageView, this image will be used as a placeholder, waiting for the web image to be loaded.
Most common use is in conjunction with an UITableView:
- Place an UIImageView as a subview of your UITableViewCell in Interface Builder
- Set its class to DMImageView in the identity panel.
- Optionally set an image from your bundle to this UIImageView, it will be used as a placeholder image waiting for the real image to be downloaded.
- In your tableView:cellForRowAtIndexPath: UITableViewDataSource method, invoke the setImageWithURL: method of the DMWebImage view with the URL of the image to download
Your done, everything will be handled for you, from parallel downloads to caching management.
### Asynchronous Image Downloader
It is possible to use the NSOperation based image downloader independently. Just create an instance of DMWebImageDownloader using its convenience constructor downloaderWithURL:target:action:.
DMWebImageDownloader *downloader = [DMWebImageDownloader downloaderWithURL:url target:self action:@selector(downloadFinishedWithImage:)];
The download will by queued immediately and the downloadFinishedWithImage: method will be called as soon as the download of image will be completed (prepare not to be called from the main thread).
### Asynchronous Image Caching
It is also possible to use the NSOperation based image cache store independently. DMImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed asynchronous so it doesn't add unnecessary latency to the UI.
The DMImageCache class provides a singleton instance for convenience but you can create your own instance if you want to create separated cache namespaces.
To lookup the cache, you use the imageForKey: method. If the method returns nil, it means the cache doesn't currently own the image. You are thus responsible of generating and caching it. The cache key is an application unique identifier for the image to cache. It is generally the absolute URL of the image.
UIImage *myCachedImage = [[DMImageCache sharedImageCache] imageFromKey:myCacheKey];
By default DMImageCache will lookup the disk cache if an image can't be found in the memory cache. You can prevent this from happening by calling the alternative method imageFromKey:fromDisk: with a negative second argument.
To store an image into the cache, you use the storeImage:forKey: method:
[[DMImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey];
By default, the image will be stored in memory cache as well as on disk cache (asynchronously). If you want only the memory cache, use the alternative method storeImage:forKey:toDisk: with a negative third argument.
Future Enhancements
-------------------