js交互


oc调用js

//[myWebView stringByEvaluatingJavaScriptFromString:@"submitForm();"];




//   js调用oc

//网页加载完成调用此方法

//    //首先创建JSContext 对象(此处通过当前webView的键获取到jscontext

//    context1 =[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

//    //第二种情况,js是通过对象调用的,我们假设js里面有一个对象 testobject 在调用方法

//    //首先创建我们新建类的对象,将他赋值给js的对象

//    Js_Lei *testJO=[Js_Lei new];

//    context1[@"TrcbankApp"]=testJO;

//    testJO.delegate = self;




Js_Lei类.h

import <Foundation/Foundation.h>

#import <JavaScriptCore/JavaScriptCore.h>


//首先创建一个实现了JSExport协议的协议

@protocol TestJSObjectProtocol <JSExport>

//此处我们测试几种参数的情况

-(void)showLoading;

-(void)hideLoading;


@end

@protocol JSObjectData <NSObject>


//此为代理方法名

- (void)gotoNextVC1;

- (void)gotoNextVC2;


@end

@interface Js_Lei : NSObject<TestJSObjectProtocol>

@property (nonatomic , assign) id<JSObjectData>delegate;


@end



Js_Lei类.m

#import "Js_Lei.h"


@implementation Js_Lei


-(void)showLoading

{

//    NSLog(@"this is ios TestNOParameter");

    [self.delegate gotoNextVC1];


}

-(void)hideLoading

{

//    NSLog(@"this is ios TestOneParameter");

    [self.delegate gotoNextVC2];


}



@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值