marinofaggiana 6 years ago
parent
commit
e2be35eb8b
1 changed files with 10 additions and 3 deletions
  1. 10 3
      iOSClient/Media/NCMedia.swift

+ 10 - 3
iOSClient/Media/NCMedia.swift

@@ -522,9 +522,16 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        let key = sectionDatasource.sections.object(at: section)
-        let datasource = sectionDatasource.sectionArrayRow.object(forKey: key) as! [tableMetadata]
-        return datasource.count
+        
+        var numberOfItemsInSection: Int = 0
+        
+        if section < sectionDatasource.sections.count {
+            let key = sectionDatasource.sections.object(at: section)
+            let datasource = sectionDatasource.sectionArrayRow.object(forKey: key) as! [tableMetadata]
+            numberOfItemsInSection = datasource.count
+        }
+        
+        return numberOfItemsInSection
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {