diff --git a/EGOImageLoader/EGOImageLoadConnection.m b/EGOImageLoader/EGOImageLoadConnection.m index 435225a..8a9cd1a 100644 --- a/EGOImageLoader/EGOImageLoadConnection.m +++ b/EGOImageLoader/EGOImageLoadConnection.m @@ -54,7 +54,12 @@ - (void)start { cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:self.timeoutInterval]; [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"]; - _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; + _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO]; + [_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; + [_connection start]; + + NSLog(@"%@", request); + [request release]; } diff --git a/EGOImageLoader/EGOImageLoader.m b/EGOImageLoader/EGOImageLoader.m index 32a619a..4fa5b09 100644 --- a/EGOImageLoader/EGOImageLoader.m +++ b/EGOImageLoader/EGOImageLoader.m @@ -133,7 +133,7 @@ - (EGOImageLoadConnection*)loadImageForURL:(NSURL*)aURL { [currentConnections setObject:connection forKey:aURL]; self.currentConnections = [[currentConnections copy] autorelease]; [connectionsLock unlock]; - [connection performSelector:@selector(start) withObject:nil afterDelay:0.01]; + [connection performSelector:@selector(start) withObject:nil afterDelay:0.01 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; [connection release]; return connection; diff --git a/EGOImageView/EGOImageView.h b/EGOImageView/EGOImageView.h index 5f331aa..8b619d1 100644 --- a/EGOImageView/EGOImageView.h +++ b/EGOImageView/EGOImageView.h @@ -42,7 +42,9 @@ @property(nonatomic,retain) NSURL* imageURL; @property(nonatomic,retain) UIImage* placeholderImage; -@property(nonatomic,assign) id delegate; +@property(nonatomic,assign) IBOutlet id delegate; +@property(nonatomic, readonly) BOOL loadedFromCache; + @end @protocol EGOImageViewDelegate diff --git a/EGOImageView/EGOImageView.m b/EGOImageView/EGOImageView.m index e87b7c6..bf7bd7c 100644 --- a/EGOImageView/EGOImageView.m +++ b/EGOImageView/EGOImageView.m @@ -29,6 +29,7 @@ @implementation EGOImageView @synthesize imageURL, placeholderImage, delegate; +@synthesize loadedFromCache = _loadedFromCache; - (id)initWithPlaceholderImage:(UIImage*)anImage { return [self initWithPlaceholderImage:anImage delegate:nil]; @@ -63,13 +64,14 @@ - (void)setImageURL:(NSURL *)aURL { if(anImage) { self.image = anImage; - + _loadedFromCache = YES; // trigger the delegate callback if the image was found in the cache if([self.delegate respondsToSelector:@selector(imageViewLoadedImage:)]) { [self.delegate imageViewLoadedImage:self]; } } else { self.image = self.placeholderImage; + _loadedFromCache = NO; } } @@ -87,6 +89,7 @@ - (void)imageLoaderDidLoad:(NSNotification*)notification { UIImage* anImage = [[notification userInfo] objectForKey:@"image"]; self.image = anImage; [self setNeedsDisplay]; + _loadedFromCache = NO; if([self.delegate respondsToSelector:@selector(imageViewLoadedImage:)]) { [self.delegate imageViewLoadedImage:self];