17
17
#import " JSWKInterceptViewController.h"
18
18
#import " JSWKBridgeCallAppViewController.h"
19
19
#import " JSWKBridgeCallJSViewController.h"
20
+ #import " JSHomeTableViewCell.h"
20
21
21
22
@interface JSHomeViewController ()
22
23
/* *
@@ -36,26 +37,23 @@ - (void)viewDidLoad {
36
37
37
38
self.title = @" iOS & H5 交互" ;
38
39
self.navigationItem .backBarButtonItem = [[UIBarButtonItem alloc ] initWithTitle: @" 返回" style: UIBarButtonItemStyleDone target: nil action: nil ];
40
+ [self .tableView registerNib: [UINib nibWithNibName: NSStringFromClass ([JSHomeTableViewCell class ]) bundle: nil ] forCellReuseIdentifier: NSStringFromClass ([JSHomeTableViewCell class ])];
39
41
}
40
42
41
43
- (NSArray <NSArray<JSHomeModel *> *> *)modelArray {
42
44
if (!_modelArray) {
43
- JSHomeModel *uiwebviewIntercept = [[JSHomeModel alloc ] initWithTitle :@" JS调用APP方法 - 拦截跳转 - UIWebView " targetClass: [JSUIInterceptViewController class ]];
44
- JSHomeModel *wkwebviewIntercept = [[JSHomeModel alloc ] initWithTitle :@" JS调用APP方法 - 拦截跳转 - WKWebView " targetClass: [JSWKInterceptViewController class ]];
45
+ JSHomeModel *uiwebviewIntercept = [[JSHomeModel alloc ] initWithType :@" UIWebView " jsCallNative: @" 拦截跳转" nativeCallJS: @" stringByEvaluatingJavaScriptFromString: " targetClass: [JSUIInterceptViewController class ]];
46
+ JSHomeModel *wkwebviewIntercept = [[JSHomeModel alloc ] initWithType :@" WKWebView " jsCallNative: @" 拦截跳转" nativeCallJS: @" evaluateJavaScript:completionHandler " targetClass: [JSWKInterceptViewController class ]];
45
47
46
- JSHomeModel *uiwebviewJsContext = [[JSHomeModel alloc ] initWithTitle :@" JS调用APP方法 - JSContext - UIWebView " targetClass: [JSUIJsContextViewController class ]];
48
+ JSHomeModel *uiwebviewJsContext = [[JSHomeModel alloc ] initWithType :@" UIWebView " jsCallNative: @" JsContextExport " nativeCallJS: @" evaluateScript: 或 callWithArguments: " targetClass: [JSUIJsContextViewController class ]];
47
49
48
- JSHomeModel *wkJsbridgeCallApp = [[JSHomeModel alloc ] initWithTitle: @" JS调用APP方法 - JsBridge - WKWebView" targetClass: [JSWKBridgeCallAppViewController class ]];
49
- JSHomeModel *uiJsbridgeCallApp = [[JSHomeModel alloc ] initWithTitle: @" JS调用APP方法 - JsBridge - UIWebView" targetClass: [JSUIBridgeCallAppViewController class ]];
50
-
51
- JSHomeModel *wkJsbridgeCallJS = [[JSHomeModel alloc ] initWithTitle: @" APP调用JS方法 - JsBridge - WKWebView" targetClass: [JSWKBridgeCallJSViewController class ]];
52
- JSHomeModel *uiJsbridgeCallJS = [[JSHomeModel alloc ] initWithTitle: @" APP调用JS方法 - JsBridge - UIWebView" targetClass: [JSUIBridgeCallJSViewController class ]];
50
+ JSHomeModel *uiJsbridgeCallApp = [[JSHomeModel alloc ] initWithType: @" UIWebView" jsCallNative: @" WebViewJavascriptBridge" nativeCallJS: @" callHandler" targetClass: [JSUIBridgeCallAppViewController class ]];
51
+ JSHomeModel *wkJsbridgeCallApp = [[JSHomeModel alloc ] initWithType: @" WKWebView" jsCallNative: @" WebViewJavascriptBridge" nativeCallJS: @" callHandler" targetClass: [JSWKBridgeCallAppViewController class ]];
53
52
54
53
_modelArray = @[
55
54
@[uiwebviewIntercept, wkwebviewIntercept],
56
55
@[uiwebviewJsContext],
57
56
@[uiJsbridgeCallApp, wkJsbridgeCallApp],
58
- @[uiJsbridgeCallJS, wkJsbridgeCallJS]
59
57
];
60
58
}
61
59
return _modelArray;
@@ -70,21 +68,20 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
70
68
}
71
69
72
70
- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath {
73
- static NSString *identify = @" ID " ;
74
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: identify ];
75
- if (! cell) {
76
- cell = [[UITableViewCell alloc ] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: identify] ;
77
- }
78
- cell. textLabel . text = self. modelArray [indexPath.section][indexPath.row]. title ;
71
+ JSHomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: NSStringFromClass ([JSHomeTableViewCell class ])] ;
72
+ JSHomeModel *model = self. modelArray [indexPath.section][indexPath.row ];
73
+ cell. typeLabel . text = model. webViewType ;
74
+ cell. jsCallNativeLabel . text = model. jsCallNative ;
75
+ cell. nativeCallJsLabel . text = model. nativeCallJs ;
76
+
79
77
return cell;
80
78
}
81
79
82
80
- (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath {
83
81
JSHomeModel *model = self.modelArray [indexPath.section][indexPath.row];
84
82
85
- UIViewController *vc = [[model.targetClass alloc ] init ];
86
- vc.title = model.title ;
87
-
83
+ UIViewController *vc = (UIViewController *)[[model.targetClass alloc ] init ];
84
+
88
85
[self .navigationController pushViewController: vc animated: YES ];
89
86
}
90
87
@end
0 commit comments