...
|
...
|
@@ -58,25 +58,25 @@ it, et voila! |
|
|
How To Use It
|
|
|
-------------
|
|
|
|
|
|
### DMWebImageView as UIImageWeb Drop-In Replacement
|
|
|
### SDWebImageView as UIImageWeb Drop-In Replacement
|
|
|
|
|
|
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.
|
|
|
- Set its class to SDImageView 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
|
|
|
method of the SDWebImage 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:.
|
|
|
of SDWebImageDownloader using its convenience constructor downloaderWithURL:target:action:.
|
|
|
|
|
|
downloader = [DMWebImageDownloader downloaderWithURL:url
|
|
|
downloader = [SDWebImageDownloader downloaderWithURL:url
|
|
|
target:self
|
|
|
action:@selector(downloadFinishedWithImage:)];
|
|
|
|
...
|
...
|
@@ -85,11 +85,11 @@ soon as the download of image will be completed (prepare not to be called from t |
|
|
|
|
|
### Asynchronous Image Caching
|
|
|
|
|
|
It is also possible to use the NSOperation based image cache store independently. DMImageCache
|
|
|
It is also possible to use the NSOperation based image cache store independently. SDImageCache
|
|
|
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
|
|
|
The SDImageCache 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
|
...
|
...
|
@@ -97,15 +97,15 @@ doesn't currently own the image. You are thus responsible of generating and cach |
|
|
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];
|
|
|
UIImage *myCachedImage = [[SDImageCache sharedImageCache] imageFromKey:myCacheKey];
|
|
|
|
|
|
By default DMImageCache will lookup the disk cache if an image can't be found in the memory cache.
|
|
|
By default SDImageCache 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];
|
|
|
[[SDImageCache 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
|
...
|
...
|
|