Browse Source

Fix Crash Thumbnail + collectionView ReloadData ?

Marino Faggiana 6 years ago
parent
commit
9ab4c45864
1 changed files with 24 additions and 2 deletions
  1. 24 2
      iOSClient/Photos/CCPhotos.m

+ 24 - 2
iOSClient/Photos/CCPhotos.m

@@ -40,6 +40,10 @@
     
     TOScrollBar *scrollBar;
     NSMutableDictionary *saveEtagForStartDirectory;
+    
+    // Fix Crash Thumbnail + collectionView ReloadData ?
+    NSInteger counterThumbnail;
+    BOOL collectionViewReloadData;
 }
 @end
 
@@ -96,6 +100,10 @@
     scrollBar = [TOScrollBar new];
     [self.collectionView to_addScrollBar:scrollBar];
     
+    // Fix Crash Thumbnail + collectionView ReloadData ?
+    counterThumbnail = 0;
+    collectionViewReloadData = NO;
+    
     scrollBar.handleTintColor = [NCBrandColor sharedInstance].brand;
     scrollBar.handleWidth = 20;
     scrollBar.handleMinimiumHeight = 20;
@@ -442,11 +450,20 @@
             return;
     }
     
+    counterThumbnail++;
+    
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
     [ocNetworking downloadThumbnailWithDimOfThumbnail:@"m" fileID:metadata.fileID fileNamePath:[CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:saveServerUrl activeUrl:appDelegate.activeUrl] fileNameView:metadata.fileNameView completion:^(NSString *message, NSInteger errorCode) {
+        counterThumbnail--;
         if (errorCode == 0 && [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] && [self indexPathIsValid:indexPath]) {
             [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
         }
+        
+        // Fix Crash Thumbnail + collectionView ReloadData ?
+        if (counterThumbnail == 0 && collectionViewReloadData == YES) {
+            [self.collectionView reloadData];
+            collectionViewReloadData = NO;
+        }
     }];
 }
 
@@ -574,8 +591,13 @@
                 [self setUINavigationBarSelected];
             else
                 [self setUINavigationBarDefault];
-                
-            [self.collectionView reloadData];
+            
+            // Fix Crash Thumbnail + collectionView ReloadData ?
+            collectionViewReloadData = YES;
+            if (counterThumbnail == 0) {
+                [self.collectionView reloadData];
+                collectionViewReloadData = NO;
+            }
         });
     });
 }