MWPhotoBrowser
MWPhotoBrowser copied to clipboard
Delegate `- photoBrowser:didDisplayPhotoAtIndex:` is not called in some situations
The delegate method:
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index can not be called in some situations.
For example, if one MWPhotoBrowser object initialized and displayed the first image, then, initialize another MWPhotoBrowser object, the delegate method is not called when first image of the later object is displayed.
I noticed that in implementation, there is one line here to declare the prevIndex variable:
static NSUInteger prevIndex = NSUIntegerMax;
I think static makes the prevIndex shared between objects (even if the object is dealloced, it behaves like a class variable in other language's term). I guess make prevIndex an instance variable may fix the problem.
Here is a possible fix:
diff --git a/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.m b/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.m
index 1867a66..7a36755 100644
--- a/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.m
+++ b/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.m
@@ -31,6 +31,7 @@
// Paging
NSMutableSet *_visiblePages, *_recycledPages;
NSUInteger _currentPageIndex;
+ NSUInteger _previousPageIndex;
NSUInteger _pageIndexBeforeRotation;
// Navigation & controls
@@ -167,6 +168,7 @@
self.hidesBottomBarWhenPushed = YES;
_photoCount = NSNotFound;
_currentPageIndex = 0;
+ _previousPageIndex = NSUIntegerMax;
_displayActionButton = YES;
_displayNavArrows = NO;
_zoomPhotosToFill = YES;
@@ -879,11 +881,10 @@
}
// Notify delegate
- static NSUInteger prevIndex = NSUIntegerMax;
- if (index != prevIndex) {
+ if (index != _previousPageIndex) {
if ([_delegate respondsToSelector:@selector(photoBrowser:didDisplayPhotoAtIndex:)])
[_delegate photoBrowser:self didDisplayPhotoAtIndex:index];
- prevIndex = index;
+ _previousPageIndex = index;
}
// Update nav