Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a .01 second delay to the start of an image load, which will pr…

…event the unneccessary starting of an image download while scrolling in a table view, that will be cancelled right away, anyway.
  • Loading branch information...
commit 43beda1c8cba4adf192e4ecaa619e00f63110bd0 1 parent 8392d28
@shnhrrsn shnhrrsn authored
View
6 EGOImageLoader/EGOImageLoadConnection.h
@@ -3,7 +3,7 @@
// EGOImageLoading
//
// Created by Shaun Harrison on 12/1/09.
-// Copyright 2009 enormego. All rights reserved.
+// Copyright 2009-2010 enormego. All rights reserved.
//
// This work is licensed under the Creative Commons GNU General Public License License.
// To view a copy of this license, visit http://creativecommons.org/licenses/GPL/2.0/
@@ -41,6 +41,6 @@
@end
@protocol EGOImageLoadConnectionDelegate<NSObject>
-- (void)connectionDidFinishLoading:(EGOImageLoadConnection *)connection;
-- (void)connection:(EGOImageLoadConnection *)connection didFailWithError:(NSError *)error;
+- (void)imageLoadConnectionDidFinishLoading:(EGOImageLoadConnection *)connection;
+- (void)imageLoadConnection:(EGOImageLoadConnection *)connection didFailWithError:(NSError *)error;
@end
View
17 EGOImageLoader/EGOImageLoadConnection.m
@@ -3,7 +3,7 @@
// EGOImageLoading
//
// Created by Shaun Harrison on 12/1/09.
-// Copyright 2009 enormego. All rights reserved.
+// Copyright 2009-2010 enormego. All rights reserved.
//
// This work is licensed under the Creative Commons GNU General Public License License.
// To view a copy of this license, visit http://creativecommons.org/licenses/GPL/2.0/
@@ -32,14 +32,11 @@ - (void)start {
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:self.timeoutInterval];
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
-
_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
- NSLog(@"Starting: %@", _connection);
[request release];
}
- (void)cancel {
- NSLog(@"Cancelling: %@", _connection);
[_connection cancel];
}
@@ -59,17 +56,17 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if(connection != _connection) return;
- NSLog(@"%@", NSStringFromSelector(_cmd));
- if([self.delegate respondsToSelector:_cmd]) {
- [self.delegate connectionDidFinishLoading:self];
+
+ if([self.delegate respondsToSelector:@selector(imageLoadConnectionDidFinishLoading:)]) {
+ [self.delegate imageLoadConnectionDidFinishLoading:self];
}
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
if(connection != _connection) return;
- NSLog(@"%@", NSStringFromSelector(_cmd));
- if([self.delegate respondsToSelector:_cmd]) {
- [self.delegate connection:self didFailWithError:error];
+
+ if([self.delegate respondsToSelector:@selector(imageLoadConnection:didFailWithError:)]) {
+ [self.delegate imageLoadConnection:self didFailWithError:error];
}
}
View
2  EGOImageLoader/EGOImageLoader.h
@@ -3,7 +3,7 @@
// EGOImageLoading
//
// Created by Shaun Harrison on 9/15/09.
-// Copyright 2009 enormego. All rights reserved.
+// Copyright 2009-2010 enormego. All rights reserved.
//
// This work is licensed under the Creative Commons GNU General Public License License.
// To view a copy of this license, visit http://creativecommons.org/licenses/GPL/2.0/
View
10 EGOImageLoader/EGOImageLoader.m
@@ -3,7 +3,7 @@
// EGOImageLoading
//
// Created by Shaun Harrison on 9/15/09.
-// Copyright 2009 enormego. All rights reserved.
+// Copyright 2009-2010 enormego. All rights reserved.
//
// This work is licensed under the Creative Commons GNU General Public License License.
// To view a copy of this license, visit http://creativecommons.org/licenses/GPL/2.0/
@@ -68,6 +68,7 @@ - (BOOL)isLoadingImageURL:(NSURL*)aURL {
- (void)cancelLoadForURL:(NSURL*)aURL {
EGOImageLoadConnection* connection = [self loadingConnectionForURL:aURL];
+ [NSObject cancelPreviousPerformRequestsWithTarget:connection selector:@selector(start) object:nil];
[connection cancel];
[self cleanUpConnection:connection];
}
@@ -93,8 +94,7 @@ - (void)loadImageForURL:(NSURL*)aURL observer:(id<EGOImageLoaderObserver>)observ
[currentConnections setObject:connection forKey:aURL];
self.currentConnections = [[currentConnections copy] autorelease];
[connectionsLock unlock];
-
- [connection start];
+ [connection performSelector:@selector(start) withObject:nil afterDelay:0.01];
[connection release];
}
@@ -127,7 +127,7 @@ - (void)removeObserver:(id<EGOImageLoaderObserver>)observer forURL:(NSURL*)aURL
#pragma mark -
#pragma mark URL Connection delegate methods
-- (void)connectionDidFinishLoading:(EGOImageLoadConnection *)connection {
+- (void)imageLoadConnectionDidFinishLoading:(EGOImageLoadConnection *)connection {
UIImage* anImage = [UIImage imageWithData:connection.responseData];
if(!anImage) {
@@ -153,7 +153,7 @@ - (void)connectionDidFinishLoading:(EGOImageLoadConnection *)connection {
[self cleanUpConnection:connection];
}
-- (void)connection:(EGOImageLoadConnection *)connection didFailWithError:(NSError *)error {
+- (void)imageLoadConnection:(EGOImageLoadConnection *)connection didFailWithError:(NSError *)error {
[currentConnections removeObjectForKey:connection.imageURL];
self.currentConnections = [[currentConnections copy] autorelease];
Please sign in to comment.
Something went wrong with that request. Please try again.