Explorar o código

PDFViewer(iOS) - 书签移除问题

dinglingui hai 1 ano
pai
achega
ac91893836

+ 17 - 6
ComPDFKit_Tools/ComPDFKit_Tools/Viewer/PDFBookmark/CPDFBookmarkViewController.m

@@ -84,13 +84,13 @@
 - (void)reloadData {
     if ([self.pdfView.document bookmarks].count > 0) {
         self.bookmarks = [self.pdfView.document bookmarks];
-        [self.tableView reloadData];
         self.tableView.hidden = NO;
         self.noDataLabel.hidden = YES;
     } else {
         self.tableView.hidden = YES;
         self.noDataLabel.hidden = NO;
     }
+    [self.tableView reloadData];
 }
 
 - (void)createGestureRecognizer {
@@ -135,14 +135,25 @@
         [alert addAction:addAction];
         [self presentViewController:alert animated:YES completion:nil];
     } else {
-        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
-                                                               style:UIAlertActionStyleCancel
-                                                             handler:nil];
+        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
+                                                               style:UIAlertActionStyleDefault
+                                                             handler:^(UIAlertAction * _Nonnull action) {
+            [self.pdfView.document removeBookmarkForPageIndex:self.pdfView.currentPageIndex];
+            CPDFPage *page = [self.pdfView.document pageAtIndex:self.pdfView.currentPageIndex];
+            [self.pdfView setNeedsDisplayForPage:page];
+            [self.tableView setEditing:NO animated:YES];
+            [self.tableView setUserInteractionEnabled:YES];
+            [self reloadData];
+        }];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
+        
         UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
                                                                        message:NSLocalizedString(@"Do you want to remove old mark?", nil)
                                                                 preferredStyle:UIAlertControllerStyleAlert];
         [alert addAction:cancelAction];
-    
+        [alert addAction:okAction];
+
         [self presentViewController:alert animated:YES completion:nil];
     }
 }
@@ -219,7 +230,7 @@
         CPDFBookmark *bookmark = self.bookmarks[indexPath.row];
         [self.pdfView.document removeBookmarkForPageIndex:bookmark.pageIndex];
         
-        CPDFPage *page = [self.pdfView.document pageAtIndex:self.pdfView.currentPageIndex];
+        CPDFPage *page = [self.pdfView.document pageAtIndex:bookmark.pageIndex];
         [self.pdfView setNeedsDisplayForPage:page];
         
         NSMutableArray *bookmarks = (NSMutableArray *)self.bookmarks;