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

            });

     

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

  • 相关阅读:
    SmartTimer——一种基于STM32的轻量级时钟调度器
    Python2/3中的urllib库
    Python 解析构建数据大杂烩 -- csv、xml、json、excel
    Python2/3 中执行外部命令(Linux)和程序(exe) -- 子进程模块 subprocess
    Python 中的命令行参数处理 -- argparse、optparse、getopt
    Linux 定时循环执行 python 脚本
    Python2/3的中、英文字符编码与解码输出: UnicodeDecodeError: 'ascii' codec can't decode/encode
    在windows下使用Qt5开发GTK3图形界面应用程序
    qt编译的基于xlib cairo的桌面程序
    debian安装dwm窗口管理器
  • 原文地址:https://www.cnblogs.com/yulehuayuan/p/6432794.html
Copyright © 2011-2022 走看看