diff --git a/examples/photos/NetworkPhotoAlbums/src/DribbblePhotoAlbumViewController.m b/examples/photos/NetworkPhotoAlbums/src/DribbblePhotoAlbumViewController.m index 683533f02..8c200006f 100644 --- a/examples/photos/NetworkPhotoAlbums/src/DribbblePhotoAlbumViewController.m +++ b/examples/photos/NetworkPhotoAlbums/src/DribbblePhotoAlbumViewController.m @@ -261,6 +261,9 @@ - (void)photoAlbumScrollView: (NIPhotoAlbumScrollView *)photoAlbumScrollView for (NIOperation* op in [self.queue operations]) { if (op.tag == photoIndex) { [op cancel]; + + [self didCancelRequestWithPhotoSize:NIPhotoScrollViewPhotoSizeOriginal + photoIndex:photoIndex]; } } } diff --git a/examples/photos/NetworkPhotoAlbums/src/FacebookPhotoAlbumViewController.m b/examples/photos/NetworkPhotoAlbums/src/FacebookPhotoAlbumViewController.m index 6f339423b..314554d0a 100644 --- a/examples/photos/NetworkPhotoAlbums/src/FacebookPhotoAlbumViewController.m +++ b/examples/photos/NetworkPhotoAlbums/src/FacebookPhotoAlbumViewController.m @@ -285,6 +285,9 @@ - (void)photoAlbumScrollView: (NIPhotoAlbumScrollView *)photoAlbumScrollView for (NIOperation* op in [self.queue operations]) { if (op.tag == photoIndex) { [op cancel]; + + [self didCancelRequestWithPhotoSize:NIPhotoScrollViewPhotoSizeOriginal + photoIndex:photoIndex]; } } } diff --git a/examples/photos/NetworkPhotoAlbums/src/NetworkPhotoAlbumViewController.h b/examples/photos/NetworkPhotoAlbums/src/NetworkPhotoAlbumViewController.h index 8a17e34b7..13084086f 100644 --- a/examples/photos/NetworkPhotoAlbums/src/NetworkPhotoAlbumViewController.h +++ b/examples/photos/NetworkPhotoAlbums/src/NetworkPhotoAlbumViewController.h @@ -101,4 +101,7 @@ photoSize: (NIPhotoScrollViewPhotoSize)photoSize photoIndex: (NSInteger)photoIndex; +- (void)didCancelRequestWithPhotoSize:(NIPhotoScrollViewPhotoSize)photoSize + photoIndex:(NSInteger)photoIndex; + @end diff --git a/examples/photos/NetworkPhotoAlbums/src/NetworkPhotoAlbumViewController.m b/examples/photos/NetworkPhotoAlbums/src/NetworkPhotoAlbumViewController.m index 4c4d54315..f7a07de58 100644 --- a/examples/photos/NetworkPhotoAlbums/src/NetworkPhotoAlbumViewController.m +++ b/examples/photos/NetworkPhotoAlbums/src/NetworkPhotoAlbumViewController.m @@ -57,12 +57,27 @@ - (NSString *)cacheKeyForPhotoIndex:(NSInteger)photoIndex { /////////////////////////////////////////////////////////////////////////////////////////////////// -- (void)requestImageFromSource: (NSString *)source - photoSize: (NIPhotoScrollViewPhotoSize)photoSize - photoIndex: (NSInteger)photoIndex { +- (NSInteger)identifierWithPhotoSize:(NIPhotoScrollViewPhotoSize)photoSize + photoIndex:(NSInteger)photoIndex { BOOL isThumbnail = (NIPhotoScrollViewPhotoSizeThumbnail == photoSize); NSInteger identifier = isThumbnail ? -(photoIndex + 1) : photoIndex; - NSNumber* identifierKey = [NSNumber numberWithInt:identifier]; + return identifier; +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////// +- (id)identifierKeyFromIdentifier:(NSInteger)identifier { + return [NSNumber numberWithInt:identifier]; +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////// +- (void)requestImageFromSource:(NSString *)source + photoSize:(NIPhotoScrollViewPhotoSize)photoSize + photoIndex:(NSInteger)photoIndex { + BOOL isThumbnail = (NIPhotoScrollViewPhotoSizeThumbnail == photoSize); + NSInteger identifier = [self identifierWithPhotoSize:photoSize photoIndex:photoIndex]; + id identifierKey = [self identifierKeyFromIdentifier:identifier]; // Avoid duplicating requests. if ([_activeRequests containsObject:identifierKey]) { @@ -77,7 +92,7 @@ - (void)requestImageFromSource: (NSString *)source // Set an negative index for thumbnail requests so that they don't get cancelled by // photoAlbumScrollView:stopLoadingPhotoAtIndex: - readOp.tag = isThumbnail ? -(photoIndex + 1) : photoIndex; + readOp.tag = identifier; NSString* photoIndexKey = [self cacheKeyForPhotoIndex:photoIndex]; @@ -135,6 +150,15 @@ - (void)requestImageFromSource: (NSString *)source } +/////////////////////////////////////////////////////////////////////////////////////////////////// +- (void)didCancelRequestWithPhotoSize:(NIPhotoScrollViewPhotoSize)photoSize + photoIndex:(NSInteger)photoIndex { + NSInteger identifier = [self identifierWithPhotoSize:photoSize photoIndex:photoIndex]; + id identifierKey = [self identifierKeyFromIdentifier:identifier]; + [_activeRequests removeObject:identifierKey]; +} + + /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// #pragma mark -