Sfoglia il codice sorgente

1.修改CommonEditor WebCell高度改变条件。

Pen Li 8 anni fa
parent
commit
d4a0d5038b

+ 6 - 2
RedAnt ERP Mobile/common/CommonEditor/CommonEditorViewController.m

@@ -5962,7 +5962,10 @@
     NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
     NSString* control = [item_json valueForKey:@"control"];
     id height_obj = [item_json objectForKey:@"height"];
-    if ([control isEqualToString:@"webview"] && height_obj == nil) {
+    
+    NSLog(@"indexPath: %@ origin height: %@ currentHeight: %f",indexPath,height_obj,contentHeight);
+    
+    if ([control isEqualToString:@"webview"] && [height_obj floatValue] != contentHeight) {
         // 更新数据
         [item_json setObject:@(contentHeight) forKey:@"height"];
         
@@ -5975,7 +5978,8 @@
 //        [self.editorTable beginUpdates];
 //        [self.editorTable endUpdates];
         
-//        [self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
+        
+        [self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
     }
     
 }

+ 11 - 3
RedAnt ERP Mobile/common/CommonEditor/CommonEditorWebCell.m

@@ -40,13 +40,21 @@
     return self;
 }
 
+- (void)dealloc {
+    [self removeObserver:self forKeyPath:@"self.webview.scrollView.frame"];
+}
+
 - (void)setup {
     self.webview.scrollView.bounces=NO;
     self.webview.scrollView.directionalLockEnabled = true;
+    
+    [self addObserver:self forKeyPath:@"self.webview.scrollView.frame" options:NSKeyValueObservingOptionNew context:nil];
 }
 
-- (void)layoutSubviews {
-    [super layoutSubviews];
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
+    if ([keyPath isEqualToString:@"self.webview.scrollView.frame"]) {
+        [self updateContentHeight];
+    }
 }
 
 #pragma mark - Web Delegate
@@ -54,7 +62,7 @@
 - (void)updateContentHeight {
     
     NSString *h_str = [self.webview stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
-    float h = [h_str floatValue] + 1;
+    float h = [h_str floatValue];
     
     if (self.webDelegate) {
         [self.webDelegate commonEditorWebCell:self didChangeContentHeight:h];