此解决方案原理:
1、在ViewController.h中声明方法和成员变量,以及webView的委托:

2、在ViewController.m中合成成员变量并实现该方法:

3、在html页面中使用js代码调用该方法并传递2个参数(可以带中文),并使用button控件点击事件触发js方法。注意由于参数可能带有中文,故该html代码中应该有将中文转为utf-8的方法。html页面完整代码如下:





4、在ViewController的viewDidLoad方法中加载该html网页:

5、在ViewCotroller中重写WebView的委托方法shouldStartLoadWithRequest:navigationType:,并接收html网页传递过来的2个参数:


6、运行项目,点击网页中的按钮,即可实现html调用并传递参数给OC代码。
以下是完整的ViewController.m的代码:



网友评论