Pārlūkot izejas kodu

【主页】最近列表无数据状态判断

lizhe 1 gadu atpakaļ
vecāks
revīzija
8d64d147de

+ 8 - 6
PDF Office/PDF Master/Class/Home/ViewController/KMHomeHistoryFileViewController.swift

@@ -445,7 +445,7 @@ class KMHomeHistoryFileViewController: NSViewController, NSCollectionViewDelegat
         }
         
         var dateArray: [Int: URL] = [:]
-        for index in 0...self.files.count - 1 {
+        for index in 0..<self.files.count {
             let url = self.files[index]
             let attrib = try? FileManager.default.attributesOfItem(atPath: url.path) as? Dictionary<FileAttributeKey , Any>
             let fileDate: Date = attrib![FileAttributeKey(rawValue: "NSFileModificationDate")] as! Date
@@ -453,12 +453,14 @@ class KMHomeHistoryFileViewController: NSViewController, NSCollectionViewDelegat
             dateArray.updateValue(url, forKey: Int(timeInterval))
         }
         
-        let sortedKeys = dateArray.keys.sorted(by: >)
+        if dateArray.count != 0 {
+            let sortedKeys = dateArray.keys.sorted(by: >)
 
-        files.removeAll()
-        for key in sortedKeys {
-            files.append(dateArray[key]!)
-            print("\(key): \(dateArray[key]!)")
+            files.removeAll()
+            for key in sortedKeys {
+                files.append(dateArray[key]!)
+                print("\(key): \(dateArray[key]!)")
+            }
         }
         
         let fileNumber = KMPreferenceManager.shared.getData(forKey: KMPreference.documentMaximunDisplayNumberKey) as? Int ?? 10