Skip to content

Commit

Permalink
Merge pull request #216 from TackMobile/master
Browse files Browse the repository at this point in the history
Allow DTLazyImage URL request customization
  • Loading branch information
odrobnik committed Sep 10, 2012
2 parents b578251 + 4a67129 commit dec8212
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions Core/Source/DTLazyImageView.h
Expand Up @@ -18,6 +18,7 @@


@interface DTLazyImageView : UIImageView @interface DTLazyImageView : UIImageView
@property (nonatomic, strong) NSURL *url; @property (nonatomic, strong) NSURL *url;
@property (nonatomic, strong) NSMutableURLRequest *urlRequest;
@property (nonatomic, assign) BOOL shouldShowProgressiveDownload; @property (nonatomic, assign) BOOL shouldShowProgressiveDownload;


@property (nonatomic, assign) id<DTLazyImageViewDelegate> delegate; // subtle simulator bug - use assign not __unsafe_unretained @property (nonatomic, assign) id<DTLazyImageViewDelegate> delegate; // subtle simulator bug - use assign not __unsafe_unretained
Expand Down
17 changes: 14 additions & 3 deletions Core/Source/DTLazyImageView.m
Expand Up @@ -52,9 +52,14 @@ - (void)loadImageAtURL:(NSURL *)url


@autoreleasepool @autoreleasepool
{ {
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0]; if (_urlRequest == nil) {
_urlRequest = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0];
} else {
[_urlRequest setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
[_urlRequest setTimeoutInterval:10.0];
}


_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO]; _connection = [[NSURLConnection alloc] initWithRequest:_urlRequest delegate:self startImmediately:NO];
[_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; [_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
[_connection start]; [_connection start];


Expand All @@ -67,7 +72,7 @@ - (void)didMoveToSuperview
{ {
[super didMoveToSuperview]; [super didMoveToSuperview];


if (!self.image && _url && !_connection && self.superview) if (!self.image && (_url || _urlRequest) && !_connection && self.superview)
{ {
UIImage *image = [_imageCache objectForKey:_url]; UIImage *image = [_imageCache objectForKey:_url];


Expand Down Expand Up @@ -277,5 +282,11 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err


@synthesize url = _url; @synthesize url = _url;
@synthesize shouldShowProgressiveDownload; @synthesize shouldShowProgressiveDownload;
@synthesize urlRequest = _urlRequest;

- (void) setUrlRequest:(NSMutableURLRequest *)request {
_urlRequest = request;
self.url = [_urlRequest URL];
}


@end @end

0 comments on commit dec8212

Please sign in to comment.