Skip to content

Commit cd3b18b

Browse files
committed
修改iOS DEMO首页布局
1 parent 509de04 commit cd3b18b

File tree

12 files changed

+200
-29
lines changed

12 files changed

+200
-29
lines changed

iOS/JsInterface.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/* Begin PBXBuildFile section */
1010
00A1806C621D3EB9E35C5C7A /* libPods-JsInterface.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7F8F24BA95BC4A8D4709671E /* libPods-JsInterface.a */; };
11+
2B2A0043200875E500AC8FA8 /* JSHomeTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B2A0042200875E500AC8FA8 /* JSHomeTableViewCell.m */; };
12+
2B2A0045200875F200AC8FA8 /* JSHomeTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2B2A0044200875F200AC8FA8 /* JSHomeTableViewCell.xib */; };
1113
2B39E35E1FF40165009238A1 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2B39E35D1FF40165009238A1 /* Launch Screen.storyboard */; };
1214
2B39E3621FF40251009238A1 /* JSHomeModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B39E3611FF40251009238A1 /* JSHomeModel.m */; };
1315
2B65FC5F1FFBDAA0000322A1 /* intercept.html in Resources */ = {isa = PBXBuildFile; fileRef = 2B65FC5E1FFBDAA0000322A1 /* intercept.html */; };
@@ -32,6 +34,9 @@
3234
/* End PBXBuildFile section */
3335

3436
/* Begin PBXFileReference section */
37+
2B2A0041200875E500AC8FA8 /* JSHomeTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSHomeTableViewCell.h; sourceTree = "<group>"; };
38+
2B2A0042200875E500AC8FA8 /* JSHomeTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JSHomeTableViewCell.m; sourceTree = "<group>"; };
39+
2B2A0044200875F200AC8FA8 /* JSHomeTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = JSHomeTableViewCell.xib; sourceTree = "<group>"; };
3540
2B39E35D1FF40165009238A1 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
3641
2B39E3601FF40251009238A1 /* JSHomeModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSHomeModel.h; sourceTree = "<group>"; };
3742
2B39E3611FF40251009238A1 /* JSHomeModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JSHomeModel.m; sourceTree = "<group>"; };
@@ -135,6 +140,9 @@
135140
2B39E34F1FF3FEDB009238A1 /* View */ = {
136141
isa = PBXGroup;
137142
children = (
143+
2B2A0041200875E500AC8FA8 /* JSHomeTableViewCell.h */,
144+
2B2A0042200875E500AC8FA8 /* JSHomeTableViewCell.m */,
145+
2B2A0044200875F200AC8FA8 /* JSHomeTableViewCell.xib */,
138146
);
139147
path = View;
140148
sourceTree = "<group>";
@@ -359,6 +367,7 @@
359367
2B39E35E1FF40165009238A1 /* Launch Screen.storyboard in Resources */,
360368
2B65FC5F1FFBDAA0000322A1 /* intercept.html in Resources */,
361369
2B89FA481FEABCE6001349A7 /* jsbridge.html in Resources */,
370+
2B2A0045200875F200AC8FA8 /* JSHomeTableViewCell.xib in Resources */,
362371
2B65FC631FFBDAE9000322A1 /* jscontext.html in Resources */,
363372
2B89FA311FEAB1EC001349A7 /* Assets.xcassets in Resources */,
364373
);
@@ -426,6 +435,7 @@
426435
2B89FA431FEAB826001349A7 /* JSUIWebViewController.m in Sources */,
427436
2B65FC6E1FFBE72D000322A1 /* JSUIBridgeCallAppViewController.m in Sources */,
428437
2B65FC711FFBE736000322A1 /* JSUIBridgeCallJSViewController.m in Sources */,
438+
2B2A0043200875E500AC8FA8 /* JSHomeTableViewCell.m in Sources */,
429439
2B39E3621FF40251009238A1 /* JSHomeModel.m in Sources */,
430440
2B89FA461FEAB833001349A7 /* JSWKWebViewController.m in Sources */,
431441
2B69BA7F1FFD2FA6008C28A5 /* JSWKBridgeCallAppViewController.m in Sources */,

iOS/JsInterface/Class/Model/JSHomeModel.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,30 @@
1111

1212
@interface JSHomeModel : NSObject
1313
/**
14-
* 标题
14+
* WebView的类型描述
1515
*/
16-
@property(nonatomic, copy) NSString *title;
16+
@property(nonatomic, copy) NSString *webViewType;
17+
/**
18+
* JS调用Native的方式
19+
*/
20+
@property(nonatomic, copy) NSString *jsCallNative;
21+
/**
22+
* Native调用JS的方式
23+
*/
24+
@property(nonatomic, copy) NSString *nativeCallJs;
1725

1826
/**
1927
* 点击后跳转的控制器的Class
2028
*/
2129
@property(nonatomic, copy) Class targetClass;
2230

2331
/**
24-
* 构造方法,快速构建HomeModel
25-
* @param title 标题
26-
* @param targetClass 点击某一行后跳转的控制器的Class
27-
* @return 构造好的HomeModel
32+
* 构造方法
33+
* @param type WebView的类型
34+
* @param jsCallNative JS调用Native的方式
35+
* @param nativeCallJS Native调用JS的方式
36+
* @param targetClass 点击后跳转的控制器
37+
* @return 构造后的对象
2838
*/
29-
- (instancetype)initWithTitle:(NSString *)title targetClass:(Class)targetClass;
39+
- (instancetype)initWithType:(NSString *)type jsCallNative:(NSString *)jsCallNative nativeCallJS:(NSString *)nativeCallJS targetClass:(Class)targetClass;
3040
@end

iOS/JsInterface/Class/Model/JSHomeModel.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
#import "JSHomeModel.h"
1010

1111
@implementation JSHomeModel
12-
- (instancetype)initWithTitle:(NSString *)title targetClass:(Class)targetClass {
12+
- (instancetype)initWithType:(NSString *)type jsCallNative:(NSString *)jsCallNative nativeCallJS:(NSString *)nativeCallJS targetClass:(Class)targetClass {
1313
JSHomeModel *homeModel = [[JSHomeModel alloc] init];
14-
homeModel.title = title;
14+
homeModel.webViewType = type;
15+
homeModel.jsCallNative = jsCallNative;
16+
homeModel.nativeCallJs = nativeCallJS;
1517
homeModel.targetClass = targetClass;
1618
return homeModel;
1719
}
20+
1821
@end

iOS/JsInterface/Class/Pages/Home/Controller/JSHomeViewController.m

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "JSWKInterceptViewController.h"
1818
#import "JSWKBridgeCallAppViewController.h"
1919
#import "JSWKBridgeCallJSViewController.h"
20+
#import "JSHomeTableViewCell.h"
2021

2122
@interface JSHomeViewController ()
2223
/**
@@ -36,26 +37,23 @@ - (void)viewDidLoad {
3637

3738
self.title = @"iOS & H5 交互";
3839
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])];
3941
}
4042

4143
- (NSArray<NSArray<JSHomeModel *> *> *)modelArray {
4244
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]];
4547

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]];
4749

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]];
5352

5453
_modelArray = @[
5554
@[uiwebviewIntercept, wkwebviewIntercept],
5655
@[uiwebviewJsContext],
5756
@[uiJsbridgeCallApp, wkJsbridgeCallApp],
58-
@[uiJsbridgeCallJS, wkJsbridgeCallJS]
5957
];
6058
}
6159
return _modelArray;
@@ -70,21 +68,20 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
7068
}
7169

7270
- (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+
7977
return cell;
8078
}
8179

8280
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
8381
JSHomeModel *model = self.modelArray[indexPath.section][indexPath.row];
8482

85-
UIViewController *vc = [[model.targetClass alloc] init];
86-
vc.title = model.title;
87-
83+
UIViewController *vc = (UIViewController *)[[model.targetClass alloc] init];
84+
8885
[self.navigationController pushViewController:vc animated:YES];
8986
}
9087
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// JSHomeTableViewCell.h
3+
// JsInterface
4+
//
5+
// Created by 甘文鹏 on 12/01/2018.
6+
// Copyright © 2018 ganwenpeng.com. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface JSHomeTableViewCell : UITableViewCell
12+
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
13+
@property (weak, nonatomic) IBOutlet UILabel *jsCallNativeLabel;
14+
@property (weak, nonatomic) IBOutlet UILabel *nativeCallJsLabel;
15+
16+
@end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
//
3+
// JSHomeTableViewCell.m
4+
// JsInterface
5+
//
6+
// Created by 甘文鹏 on 12/01/2018.
7+
// Copyright © 2018 ganwenpeng.com. All rights reserved.
8+
//
9+
10+
#import "JSHomeTableViewCell.h"
11+
12+
@implementation JSHomeTableViewCell
13+
14+
- (void)awakeFromNib {
15+
[super awakeFromNib];
16+
17+
self.typeLabel.text = nil;
18+
self.jsCallNativeLabel.text = nil;
19+
self.nativeCallJsLabel.text = nil;
20+
}
21+
22+
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
23+
[super setSelected:selected animated:animated];
24+
25+
// Configure the view for the selected state
26+
}
27+
28+
@end

0 commit comments

Comments
 (0)