zoukankan      html  css  js  c++  java
  • OC和JS互调

    OC和JS互调 可能造成相互强引用 小技巧

        JSContext *content = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

        content[@"chongzhi"] = ^() {

            

            NSArray *thisArr = [JSContext currentArguments];

            int iValue = 0;

            if(thisArr.count > 0)

            {

                JSValue *value = thisArr.firstObject;

                DebugLog(@"value:%@",value);

                NSString *strValue = [value toString];

                DebugLog(@"strValue:%@",strValue);

                iValue = [strValue intValue];

                DebugLog(@"iValue:%d",iValue);

            }

            

            TopupController *vc = [[TopupController alloc] init];

            switch (iValue) {

                case 20:

                    vc.amount = 0;

                    break;

                case 50:

                    vc.amount = 1;

                    break;

                case 100:

                    vc.amount = 2;

                    break;

                case 200:

                    vc.amount = 3;

                    break;

                case 500:

                    vc.amount = 4;

                    break;

                default:

                    vc.amount = 0;

                    break;

            }

            //            vc.amount = 1;

            NSLog(@"vc.amount:%ld",vc.amount);

            dispatch_async(dispatch_get_main_queue(), ^{

            [self.navigationController pushViewController:vc animated:YES];

            });

     

    跳转时在主线程种可以解决

  • 相关阅读:
    类成员之静态字段和普通字段、静态方法和普通方法
    类的导出
    面向对象之继承
    面向对象之封装
    面向对象与函数式的对比
    计算器
    模拟信用卡登录程序
    /etc/fstab
    解决 Your project contains error(s),please fix them before running your applica ..
    C#之SqlDependency数据库缓存
  • 原文地址:https://www.cnblogs.com/yulehuayuan/p/6432794.html
Copyright © 2011-2022 走看看