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

Fixing bug on setting initial gallery index #7

Open
wants to merge 2 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
10 changes: 6 additions & 4 deletions RMGallery/RMGalleryView.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
RMGalleryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

NSInteger imageIndex = indexPath.row;
cell.tag = imageIndex; // mark the cell so we're sure it has not been reused when we fill it with the image

[cell.activityIndicatorView startAnimating];

__block BOOL sync = YES;
[self.galleryDataSource galleryView:self imageForIndex:indexPath.row completion:^(UIImage *image) {
[self.galleryDataSource galleryView:self imageForIndex:imageIndex completion:^(UIImage *image) {
// Check if cell was reused
NSIndexPath *currentIndexPath = [self indexPathForCell:cell];
if (!sync && [indexPath compare:currentIndexPath] != NSOrderedSame) return;
if (!sync && cell.tag != imageIndex) return;

[cell.activityIndicatorView stopAnimating];
cell.image = image;
Expand Down
10 changes: 8 additions & 2 deletions RMGallery/RMGalleryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ - (void)viewDidLoad
[self.view addGestureRecognizer:_tapGestureRecognizer];
}

- (void)viewWillAppear:(BOOL)animated
//- (void)viewWillAppear:(BOOL)animated
//{
// [super viewWillAppear:animated];
//}

- (void)viewDidLayoutSubviews
{
[super viewWillAppear:animated];
[super viewDidLayoutSubviews];

if (!_initialGalleryIndexSet)
{
// In case the gallery index was set before the view was loaded
Expand Down