Browse Source

improved code

marinofaggiana 4 years ago
parent
commit
d30da22e1d
2 changed files with 8 additions and 2 deletions
  1. 2 0
      iOSClient/CCGlobal.h
  2. 6 2
      iOSClient/Media/NCMedia.swift

+ 2 - 0
iOSClient/CCGlobal.h

@@ -45,6 +45,8 @@
 //#if TARGET_OS_SIMULATOR
 //#endif
 
+//if indexPath.section <  collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section)
+
 #define CALL_ORIGIN NSLog(@"Origin: [%@]", [[[[NSThread callStackSymbols] objectAtIndex:1] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"[]"]] objectAtIndex:1])
 #endif
 

+ 6 - 2
iOSClient/Media/NCMedia.swift

@@ -415,7 +415,9 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
                     collectionView?.reloadData()
                 } else if let row = indexes.first {
                     let indexPath = IndexPath(row: row, section: 0)
-                    collectionView?.deleteItems(at: [indexPath])
+                    if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+                        collectionView?.deleteItems(at: [indexPath])
+                    }
                 }
                 
                 self.updateMediaControlVisibility()
@@ -439,7 +441,9 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
                         collectionView?.reloadData()
                     } else if let row = indexes.first {
                         let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.deleteItems(at: [indexPath])
+                        if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+                            collectionView?.deleteItems(at: [indexPath])
+                        }
                     }
                     
                     self.updateMediaControlVisibility()