瀏覽代碼

PDFTools(iOS)-page edit 插入页面的tableview刷新问题

yangliuhua 1 年之前
父節點
當前提交
525cdc2201

+ 7 - 1
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFListView/CPDFListView+Edit.m

@@ -34,7 +34,13 @@
     
     if(self.editStatus == CEditingSelectStateEmpty){
         if(self.editingLoadType != CEditingLoadTypeText && self.editingLoadType != CEditingLoadTypeImage){
-            
+            UIMenuItem *addTextItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Add Text", nil)
+                                                                  action:@selector(addTextEditingItemAction:)];
+            UIMenuItem *addImageItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Add Image", nil)
+                                                                   action:@selector(addImageEditingItemAction:)];
+           
+            [menuItems insertObject:addImageItem atIndex:0];
+            [menuItems insertObject:addTextItem atIndex:0];
         }else if(self.editingLoadType == CEditingLoadTypeText){
             UIMenuItem *addTextItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Add Text", nil)
                                                                   action:@selector(addTextEditingItemAction:)];

+ 5 - 18
compdfkit-tools/compdfkit-tools/PageEdit/Control/CPDFPDFInsertViewController.m

@@ -51,8 +51,6 @@
 
 @property (nonatomic, strong) UITextField *rangeTextField;
 
-@property (nonatomic, strong) UIScrollView *scrcollView;
-
 @property (nonatomic, assign) CPDFPDFInsertType pdfInsertType;
 
 @end
@@ -112,20 +110,13 @@
     [self.cancelBtn addTarget:self action:@selector(buttonItemClicked_cancel:) forControlEvents:UIControlEventTouchUpInside];
     [self.headerView addSubview:self.cancelBtn];
     
-    self.scrcollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50)];
-    self.scrcollView.scrollEnabled = YES;
-    self.scrcollView.contentSize = CGSizeMake(self.view.frame.size.width, 800);
-    self.scrcollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
-    self.scrcollView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
-    [self.view addSubview:self.scrcollView];
-    
-    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-50) style:UITableViewStylePlain];
+    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50) style:UITableViewStylePlain];
     self.tableView.delegate = self;
     self.tableView.dataSource = self;
     self.tableView.rowHeight = 60.0;
-    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     self.tableView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
-    [self.scrcollView addSubview:self.tableView];
+    [self.view addSubview:self.tableView];
     
     self.isSelect = NO;
     self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
@@ -156,7 +147,6 @@
     [super viewWillLayoutSubviews];
     self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 50);
     self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 200)/2, 0, 200, 50);
-    self.scrcollView.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50);
     
     if (@available(iOS 11.0, *)) {
         self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, 40);
@@ -222,11 +212,8 @@
 }
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-    CInsertBlankPageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pageCell"];
-    if (cell == nil) {
-        cell = [[CInsertBlankPageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"pageCell"];
-        cell.delegate = self;
-    }
+    CInsertBlankPageCell *cell = [[CInsertBlankPageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"pageCell"];
+    cell.delegate = self;
     switch (indexPath.row) {
         case 0:
         {

+ 13 - 3
compdfkit-tools/compdfkit-tools/PageEdit/Control/CPDFPageEditViewController.m

@@ -105,7 +105,12 @@
     if (@available(iOS 11.0, *)) {
         self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.safeAreaInsets.top + 50);
         self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, self.view.safeAreaInsets.top, 120, 50);
-        self.collectionView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 60, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - 110 - self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom);
+        if (self.isEdit) {
+            self.collectionView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 60, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - 110 - self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom);
+        } else {
+            self.collectionView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 60, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height - 60 - self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom);
+        }
+        
         self.backBtn.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top, 50, 50);
         self.editBtn.frame = CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 70, self.view.safeAreaInsets.top, 50, 50);
         self.doneBtn.frame = CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 70, self.view.safeAreaInsets.top, 50, 50);
@@ -113,7 +118,11 @@
     } else {
         self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 120);
         self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 120)/2, 65, 120, 50);
-        self.collectionView.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 110);
+        if (self.isEdit) {
+            self.collectionView.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 110);
+        } else {
+            self.collectionView.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 60);
+        }
         self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 65, 50, 50);
         self.editBtn.frame = CGRectMake(self.view.frame.size.width - 70, 65, 50, 50);
         self.doneBtn.frame = CGRectMake(self.view.frame.size.width - 70, 65, 50, 50);
@@ -151,7 +160,7 @@
                                       animated:NO
                                 scrollPosition:UICollectionViewScrollPositionCenteredVertically];
     [self updateTitle];
-
+    [self viewWillLayoutSubviews];
 }
 
 - (void)buttonItemClicked_done:(UIButton *)button {
@@ -170,6 +179,7 @@
                                 scrollPosition:UICollectionViewScrollPositionCenteredVertically];
     
     [self updateTitle];
+    [self viewWillLayoutSubviews];
 }
 
 - (void)buttonItemClicked_back:(UIButton *)button {

+ 14 - 24
compdfkit-tools/compdfkit-tools/PageEdit/Control/CPDFPageInsertViewController.m

@@ -37,8 +37,6 @@
 
 @property (nonatomic, strong) CInsertBlankPageCell *preCell;
 
-@property (nonatomic, strong) UIScrollView *scrcollView;
-
 @property (nonatomic, assign) CPDFPageInsertType pageInsertType;
 
 @end
@@ -89,21 +87,14 @@
     [self.cancelBtn addTarget:self action:@selector(buttonItemClicked_cancel:) forControlEvents:UIControlEventTouchUpInside];
     [self.headerView addSubview:self.cancelBtn];
     
-    self.scrcollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50)];
-    self.scrcollView.scrollEnabled = YES;
-    self.scrcollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
-    self.scrcollView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
-    self.scrcollView.contentSize = CGSizeMake(self.view.frame.size.width, 800);
-    [self.view addSubview:self.scrcollView];
-    
-    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-100) style:UITableViewStylePlain];
+    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-100) style:UITableViewStylePlain];
     self.tableView.delegate = self;
     self.tableView.dataSource = self;
     self.tableView.rowHeight = UITableViewAutomaticDimension;
     self.tableView.estimatedRowHeight = 44.0;
-    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     self.tableView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
-    [self.scrcollView addSubview:self.tableView];
+    [self.view addSubview:self.tableView];
     
     self.isSelect = NO;
     self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
@@ -129,7 +120,6 @@
     [super viewWillLayoutSubviews];
     self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 50);
     self.titleLabel.frame = CGRectMake((self.view.frame.size.width - 200)/2, 0, 200, 50);
-    self.scrcollView.frame = CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50);
     
     if (@available(iOS 11.0, *)) {
         self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, 40);
@@ -169,11 +159,8 @@
 }
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-    CInsertBlankPageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pageCell"];
-    if (cell == nil) {
-        cell = [[CInsertBlankPageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"pageCell"];
-        cell.delegate = self;
-    }
+    CInsertBlankPageCell *cell = [[CInsertBlankPageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"pageCell"];
+    cell.delegate = self;
 
     switch (indexPath.row) {
         case 0:
@@ -267,6 +254,8 @@
             break;
     }
     
+    cell.delegate = self;
+    
     return cell;
 }
 
@@ -326,12 +315,13 @@
         }
         self.dataArray = (NSArray *)data;
         [self.tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
-        NSIndexPath* path = [NSIndexPath indexPathForRow:0 inSection:0];
-        CInsertBlankPageCell *cell = [self.tableView cellForRowAtIndexPath:path];
-        
-        NSInteger sizeIndex = [szieArray indexOfObject:cell.sizeLabel.text];
-        NSIndexPath *index = [NSIndexPath indexPathForItem:sizeIndex+1 inSection:0];
-        [self.tableView selectRowAtIndexPath:index animated:NO scrollPosition:UITableViewScrollPositionMiddle];
+//        [self.tableView reloadData];
+//        NSIndexPath* path = [NSIndexPath indexPathForRow:0 inSection:0];
+//        CInsertBlankPageCell *cell = [self.tableView cellForRowAtIndexPath:path];
+//
+//        NSInteger sizeIndex = [szieArray indexOfObject:cell.sizeLabel.text];
+//        NSIndexPath *index = [NSIndexPath indexPathForItem:sizeIndex+1 inSection:0];
+//        [self.tableView selectRowAtIndexPath:index animated:NO scrollPosition:UITableViewScrollPositionMiddle];
     } else {
         NSInteger t = indexPath.row;
         NSMutableArray *array = [NSMutableArray array];