Explorar el Código

1.CommonEditor增加WebCell。

Pen Li hace 8 años
padre
commit
ed334ae99d

+ 48 - 1
RedAnt ERP Mobile/common/CommonEditor/CommonEditorViewController.m

@@ -47,6 +47,7 @@
 #import "RAConvertor.h"
 #import "EnumSelectAndSortViewController.h"
 #import "CommonEditorRangeCell.h"
+#import "CommonEditorWebCell.h"
 
 
 
@@ -56,7 +57,7 @@
 
 @implementation subitem_data
 @end
-@interface CommonEditorViewController ()<CommonEditorRangeDelegate>
+@interface CommonEditorViewController ()<CommonEditorRangeDelegate,CommonEditorWebCellDelegate>
 
 @end
 
@@ -132,6 +133,7 @@
     [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Switch_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSwitch"];
     [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_TextView_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellTextView"];
     [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Range_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorRangeCell"];
+    [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Web_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorWebCell"];
 }
 
 - (void)setupEditorTable {
@@ -2700,6 +2702,11 @@
                 return 100;
             }
         }
+        else if ([control isEqualToString:@"webview"]) {
+            id h_obj = [item_json objectForKey:@"height"];
+            CGFloat height = [h_obj floatValue];
+            return height;
+        }
         
         return 80;
     } else {
@@ -3985,6 +3992,16 @@
             }
             return cell;
         }
+        else if ([control isEqualToString:@"webview"]) {
+            
+            CommonEditorWebCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorWebCell" forIndexPath:indexPath];
+            cell.webDelegate = self;
+            NSString *html_str = [item_json objectForKey:@"value"];
+            [cell.webview loadHTMLString:html_str baseURL:nil];
+//            [cell.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]]];
+            
+            return cell;
+        }
         else
         {
             CellIdentifier = @"CommonEditorCellEdit";
@@ -5933,6 +5950,36 @@
     
 }
 
+#pragma mark - WebCell Delegate
+
+- (void)commonEditorWebCell:(CommonEditorWebCell *)cell didChangeContentHeight:(CGFloat)contentHeight {
+    NSIndexPath *indexPath = [self.editorTable indexPathForCell:cell];
+    if (indexPath == nil) {
+        return;
+    }
+    
+    
+    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) {
+        // 更新数据
+        [item_json setObject:@(contentHeight) forKey:@"height"];
+        
+        NSMutableDictionary *section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
+        [section_json setObject:item_json  forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
+        [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
+        self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
+        
+//        // 调用 tableView 的 beginUpdates 和 endUpdates,更新 cell 的高度
+//        [self.editorTable beginUpdates];
+//        [self.editorTable endUpdates];
+        
+//        [self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
+    }
+    
+}
+
 @end
 
 

+ 23 - 0
RedAnt ERP Mobile/common/CommonEditor/CommonEditorWebCell.h

@@ -0,0 +1,23 @@
+//
+//  CommonEditorWebCell.h
+//  RedAnt Mobile
+//
+//  Created by Jack on 2017/11/17.
+//  Copyright © 2017年 Ray. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@class CommonEditorWebCell;
+@protocol CommonEditorWebCellDelegate <NSObject>
+
+- (void)commonEditorWebCell:(CommonEditorWebCell *)cell didChangeContentHeight:(CGFloat)contentHeight;
+
+@end
+
+@interface CommonEditorWebCell : UITableViewCell
+
+@property (nonatomic,weak) id<CommonEditorWebCellDelegate> webDelegate;
+@property (strong, nonatomic) IBOutlet UIWebView *webview;
+
+@end

+ 73 - 0
RedAnt ERP Mobile/common/CommonEditor/CommonEditorWebCell.m

@@ -0,0 +1,73 @@
+//
+//  CommonEditorWebCell.m
+//  RedAnt Mobile
+//
+//  Created by Jack on 2017/11/17.
+//  Copyright © 2017年 Ray. All rights reserved.
+//
+
+#import "CommonEditorWebCell.h"
+
+@interface CommonEditorWebCell() <UIWebViewDelegate>
+
+@end
+
+@implementation CommonEditorWebCell
+
+- (void)awakeFromNib {
+    [super awakeFromNib];
+    // Initialization code
+    [self setup];
+}
+
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
+    [super setSelected:selected animated:animated];
+
+    // Configure the view for the selected state
+}
+
+- (instancetype)initWithCoder:(NSCoder *)aDecoder {
+    if (self = [super initWithCoder:aDecoder]) {
+        [self setup];
+    }
+    return self;
+}
+
+- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
+    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
+        [self setup];
+    }
+    return self;
+}
+
+- (void)setup {
+    self.webview.scrollView.bounces=NO;
+    self.webview.scrollView.directionalLockEnabled = true;
+}
+
+- (void)layoutSubviews {
+    [super layoutSubviews];
+}
+
+#pragma mark - Web Delegate
+
+- (void)updateContentHeight {
+    
+    NSString *h_str = [self.webview stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
+    float h = [h_str floatValue] + 1;
+    
+    if (self.webDelegate) {
+        [self.webDelegate commonEditorWebCell:self didChangeContentHeight:h];
+    }
+}
+
+- (void)webViewDidFinishLoad:(UIWebView *)webView {
+    
+    [self updateContentHeight];
+}
+
+- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
+    [self updateContentHeight];
+}
+
+@end

+ 42 - 0
RedAnt ERP Mobile/common/CommonEditor/Phone_Web_Cell.xib

@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
+    <device id="retina4_7" orientation="portrait">
+        <adaptation id="fullscreen"/>
+    </device>
+    <dependencies>
+        <deployment identifier="iOS"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+    </dependencies>
+    <objects>
+        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
+        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
+        <tableViewCell contentMode="scaleToFill" restorationIdentifier="CommonEditorWebCell" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="CommonEditorWebCell" rowHeight="186" id="8eQ-NB-syn" customClass="CommonEditorWebCell">
+            <rect key="frame" x="0.0" y="0.0" width="768" height="186"/>
+            <autoresizingMask key="autoresizingMask"/>
+            <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="8eQ-NB-syn" id="ScR-YK-gMK">
+                <rect key="frame" x="0.0" y="0.0" width="768" height="185.5"/>
+                <autoresizingMask key="autoresizingMask"/>
+                <subviews>
+                    <webView userInteractionEnabled="NO" contentMode="scaleToFill" allowsInlineMediaPlayback="NO" mediaPlaybackRequiresUserAction="NO" mediaPlaybackAllowsAirPlay="NO" keyboardDisplayRequiresUserAction="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yhT-1o-dWH">
+                        <rect key="frame" x="0.0" y="0.0" width="768" height="185.5"/>
+                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                        <dataDetectorType key="dataDetectorTypes"/>
+                        <connections>
+                            <outlet property="delegate" destination="8eQ-NB-syn" id="NHg-Y2-IC5"/>
+                        </connections>
+                    </webView>
+                </subviews>
+                <constraints>
+                    <constraint firstItem="yhT-1o-dWH" firstAttribute="height" secondItem="ScR-YK-gMK" secondAttribute="height" id="6KP-m4-Tlg"/>
+                    <constraint firstItem="yhT-1o-dWH" firstAttribute="centerY" secondItem="ScR-YK-gMK" secondAttribute="centerY" id="JrV-0O-60Z"/>
+                    <constraint firstItem="yhT-1o-dWH" firstAttribute="width" secondItem="ScR-YK-gMK" secondAttribute="width" id="jxl-Ac-dHU"/>
+                    <constraint firstItem="yhT-1o-dWH" firstAttribute="centerX" secondItem="ScR-YK-gMK" secondAttribute="centerX" id="mCR-gd-B8c"/>
+                </constraints>
+            </tableViewCellContentView>
+            <connections>
+                <outlet property="webview" destination="yhT-1o-dWH" id="MWp-VM-GX6"/>
+            </connections>
+        </tableViewCell>
+    </objects>
+</document>