Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image loading now happens while scrolling in a scrollView/tableView. #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion EGOImageLoader/EGOImageLoadConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
2 changes: 1 addition & 1 deletion EGOImageLoader/EGOImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion EGOImageView/EGOImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@

@property(nonatomic,retain) NSURL* imageURL;
@property(nonatomic,retain) UIImage* placeholderImage;
@property(nonatomic,assign) id<EGOImageViewDelegate> delegate;
@property(nonatomic,assign) IBOutlet id<EGOImageViewDelegate> delegate;
@property(nonatomic, readonly) BOOL loadedFromCache;

@end

@protocol EGOImageViewDelegate<NSObject>
Expand Down
5 changes: 4 additions & 1 deletion EGOImageView/EGOImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

@implementation EGOImageView
@synthesize imageURL, placeholderImage, delegate;
@synthesize loadedFromCache = _loadedFromCache;

- (id)initWithPlaceholderImage:(UIImage*)anImage {
return [self initWithPlaceholderImage:anImage delegate:nil];
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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];
Expand Down