Permalink
Browse files

Canceling a operation removes itself from queue - Bugfix

  • Loading branch information...
MugunthKumar committed Jan 22, 2012
1 parent 2d15b4f commit b9ba2d6501b498e837abf49cb999dbbd67b30a4f
@@ -174,7 +174,7 @@
* The hostname of the engine is *NOT* prefixed.
* The image is returned to the caller via MKNKImageBlock callback block.
*/
- (void)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock;
- (MKNetworkOperation*)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock;
/*!
* @abstract Enqueues your operation into the shared queue
*
@@ -135,6 +135,8 @@ + (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
{
if (object == _sharedNetworkQueue && [keyPath isEqualToString:@"operationCount"]) {
DLog(@"*** Running: %d ***", (int) [_sharedNetworkQueue.operations count]);
[[NSNotificationCenter defaultCenter] postNotificationName:kMKNetworkEngineOperationCountChanged
object:[NSNumber numberWithInteger:[_sharedNetworkQueue operationCount]]];
#if TARGET_OS_IPHONE
@@ -370,7 +372,7 @@ -(void) enqueueOperation:(MKNetworkOperation*) operation forceReload:(BOOL) forc
[self freezeOperations];
}
- (void)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock
- (MKNetworkOperation*)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock
{
#ifdef DEBUG
// I could enable caching here, but that hits performance and inturn affects table view scrolling
@@ -398,6 +400,8 @@ - (void)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock
}];
[self enqueueOperation:op];
return op;
}
#pragma mark -
@@ -785,7 +785,8 @@ - (BOOL)isExecuting {
-(void) cancel {
if([self isFinished]) return;
if([self isFinished])
return;
[self.responseBlocks removeAllObjects];
self.responseBlocks = nil;
@@ -806,7 +807,9 @@ -(void) cancel {
self.authHandler = nil;
self.mutableData = nil;
self.isCancelled = YES;
self.isCancelled = YES;
self.state = MKNetworkOperationStateFinished; // This notifies the queue and removes the operation.
// if the operation is not removed, the spinner continues to spin, not a good UX
[super cancel];
}
@@ -14,6 +14,7 @@
@property (nonatomic, assign) IBOutlet UILabel *titleLabel;
@property (nonatomic, assign) IBOutlet UILabel *authorNameLabel;
@property (nonatomic, assign) NSString* loadingImageURLString;
@property (nonatomic, strong) NSString* loadingImageURLString;
@property (nonatomic, strong) MKNetworkOperation* imageLoadingOperation;
-(void) setFlickrData:(NSDictionary*) thisFlickrImage;
@end
@@ -13,6 +13,7 @@ @implementation FlickrCell
@synthesize authorNameLabel = authorNameLabel_;
@synthesize thumbnailImage = thumbnailImage_;
@synthesize loadingImageURLString = loadingImageURLString_;
@synthesize imageLoadingOperation = imageLoadingOperation_;
//===========================================================
// + (BOOL)automaticallyNotifiesObserversForKey:
@@ -34,6 +35,8 @@ + (BOOL)automaticallyNotifiesObserversForKey: (NSString *)theKey
-(void) prepareForReuse {
self.thumbnailImage.image = nil;
DLog(@"%@", self.imageLoadingOperation);
[self.imageLoadingOperation cancel];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
@@ -61,7 +64,7 @@ -(void) setFlickrData:(NSDictionary*) thisFlickrImage {
[thisFlickrImage objectForKey:@"farm"], [thisFlickrImage objectForKey:@"server"],
[thisFlickrImage objectForKey:@"id"], [thisFlickrImage objectForKey:@"secret"]];
[ApplicationDelegate.flickrEngine imageAtURL:[NSURL URLWithString:self.loadingImageURLString]
self.imageLoadingOperation = [ApplicationDelegate.flickrEngine imageAtURL:[NSURL URLWithString:self.loadingImageURLString]
onCompletion:^(UIImage *fetchedImage, NSURL *url, BOOL isInCache) {
if([self.loadingImageURLString isEqualToString:[url absoluteString]]) {

0 comments on commit b9ba2d6

Please sign in to comment.