DMWebImageView.m
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* This file is part of the DMWebImage package.
* (c) Dailymotion - Olivier Poitrey <rs@dailymotion.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import "DMWebImageView.h"
#import "DMImageCache.h"
#import "DMWebImageDownloader.h"
@implementation DMWebImageView
- (void)dealloc
{
[placeHolderImage release];
[currentOperation release];
[super dealloc];
}
#pragma mark RemoteImageView
- (void)setImageWithURL:(NSURL *)url
{
if (currentOperation != nil)
{
[currentOperation cancel]; // remove from queue
[currentOperation release];
currentOperation = nil;
}
// Save the placeholder image in order to re-apply it when view is reused
if (placeHolderImage == nil)
{
placeHolderImage = [self.image retain];
}
else
{
self.image = placeHolderImage;
}
UIImage *cachedImage = [[DMImageCache sharedImageCache] imageFromKey:[url absoluteString]];
if (cachedImage)
{
self.image = cachedImage;
}
else
{
currentOperation = [[DMWebImageDownloader downloaderWithURL:url target:self action:@selector(downloadFinishedWithImage:)] retain];
}
}
- (void)downloadFinishedWithImage:(UIImage *)anImage
{
self.image = anImage;
[currentOperation release];
currentOperation = nil;
}
@end