Browse Source

【优化】Appcenter 问题修复 - PDF_Reader_Pro.KMLeftSideViewController.tableView

https://appcenter.ms/users/support-pdfreaderpro.com/apps/PDF-Reader-Pro-DMG/crashes/errors/484216108u/overview
lizhe 7 months ago
parent
commit
7dc57adf6f

+ 49 - 41
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -1101,62 +1101,70 @@ extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
     func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
         if tableView.isEqual(to: self.thumbnailTableView) {
             let cell = tableView.makeView(withIdentifier: KMThumbnailTableviewCell.km_identifier, owner: self) as! KMThumbnailTableviewCell
-            let thumbnail = self.thumbnails[row]
-            cell.pageNumLabel.stringValue = thumbnail.label
-            cell.pageView.isThumb = true
-            cell.pageView.page = self.pdfDocument()?.page(at: UInt(row))
-            
-            let bks = self.listView?.document.bookmarks()
-            var hasBookmark = false
-            for bk in bks ?? [] {
-                if row == bk.pageIndex {
-                    hasBookmark = true
-                    break
+            if self.thumbnails.count > row {
+                let thumbnail = self.thumbnails[row]
+                let page = self.pdfDocument()?.page(at: UInt(row))
+                cell.pageNumLabel.stringValue = thumbnail.label
+                cell.pageView.isThumb = true
+                cell.pageView.page = page
+                
+                let bks = self.listView?.document.bookmarks()
+                var hasBookmark = false
+                for bk in bks ?? [] {
+                    if row == bk.pageIndex {
+                        hasBookmark = true
+                        break
+                    }
                 }
-            }
-            cell.bkIcon.isHidden = !hasBookmark
+                cell.bkIcon.isHidden = !hasBookmark
 
-            if (self.isDisplayPageSize) {
-                cell.sizeLabel.isHidden = false
-                //获取Page的真实尺寸
-                let page = self.pdfDocument()?.page(at: UInt(row))
-                let rect = page?.bounds(for: .cropBox) ?? .zero
-                let w =  KMPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/595 * 210))
-                let h =  KMPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/842 * 297))
-                if let data = page?.rotation, data == 90 || data == 270 {
-                    cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", h.stringToCGFloat(), w.stringToCGFloat(), KMLocalizedString("mm", nil))
+                if (self.isDisplayPageSize) {
+                    cell.sizeLabel.isHidden = false
+                    //获取Page的真实尺寸
+                    let rect = page?.bounds(for: .cropBox) ?? .zero
+                    let w =  KMPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/595 * 210))
+                    let h =  KMPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/842 * 297))
+                    if let data = page?.rotation, data == 90 || data == 270 {
+                        cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", h.stringToCGFloat(), w.stringToCGFloat(), KMLocalizedString("mm", nil))
+                    } else {
+                        cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", w.stringToCGFloat(), h.stringToCGFloat(), KMLocalizedString("mm", nil))
+                    }
                 } else {
-                    cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", w.stringToCGFloat(), h.stringToCGFloat(), KMLocalizedString("mm", nil))
+                    cell.sizeLabel.stringValue = "0 mm"
+                    cell.sizeLabel.isHidden = true
+                }
+                cell.sizeTopConstant.constant = cell.sizeLabel.isHidden ? -cell.sizeLabel.frame.size.height : 0
+                if (self.thumbnailTableView.selectedRowIndexes.contains(row)) {
+                    cell.isSelectCell = true
+                } else {
+                    cell.isSelectCell = false
                 }
-            } else {
-                cell.sizeLabel.stringValue = "0 mm"
-                cell.sizeLabel.isHidden = true
-            }
-            cell.sizeTopConstant.constant = cell.sizeLabel.isHidden ? -cell.sizeLabel.frame.size.height : 0
-            if (self.thumbnailTableView.selectedRowIndexes.contains(row)) {
-                cell.isSelectCell = true
-            } else {
-                cell.isSelectCell = false
             }
             return cell
         } else if (tableView.isEqual(to: self.findTableView)) {
             let cell = tableView.makeView(withIdentifier: KMFindTableviewCell.km_identifier, owner: self) as! KMFindTableviewCell
-             let selection = searchResults[row]
-            if let data = tableColumn?.identifier.rawValue, data == kResultsColumnId.rawValue {
-                cell.resultLabel.attributedStringValue = selection.attributedString
-                cell.resultLabel.textColor = KMAppearance.Layout.h0Color()
-            } else if let data = tableColumn?.identifier.rawValue, data == kPageColumnId.rawValue {
-                cell.resultLabel.stringValue = "\(Int(selection.selectionPageIndex) + 1)"
-                cell.resultLabel.textColor = KMAppearance.Layout.h2Color()
+            if searchResults.count > row {
+                let selection = searchResults[row]
+                if let data = tableColumn?.identifier.rawValue, data == kResultsColumnId.rawValue {
+                    cell.resultLabel.attributedStringValue = selection.attributedString
+                    cell.resultLabel.textColor = KMAppearance.Layout.h0Color()
+                } else if let data = tableColumn?.identifier.rawValue, data == kPageColumnId.rawValue {
+                    cell.resultLabel.stringValue = "\(Int(selection.selectionPageIndex) + 1)"
+                    cell.resultLabel.textColor = KMAppearance.Layout.h2Color()
+                }
             }
             return cell
         } else if tableView.isEqual(to: self.snapshotTableView) {
             let cell = tableView.makeView(withIdentifier: KMSnapshotTableViewCell.km_identifier, owner: self) as! KMSnapshotTableViewCell
             var snapshot: KMSnapshotModel?
             if self.isSearchSnapshotMode {
-                snapshot = self.searchSnapshots[row]
+                if self.searchSnapshots.count > row {
+                    snapshot = self.searchSnapshots[row]
+                }
             } else {
-                snapshot = self.snapshots[row]
+                if self.snapshots.count > row {
+                    snapshot = self.snapshots[row]
+                }
             }
             
             cell.snapshotImage.image = snapshot?.windowC?.thumbnail