如何将XCode变量传递到资源文件夹中的HTML文件? [英] How to pass an XCode variable to the HTML file in resources folder?

查看:84
本文介绍了如何将XCode变量传递到资源文件夹中的HTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIWebView从资源文件夹加载本地HTML文件。
现在,这个HTML文件里面有Javascript。

I have a UIWebView that loads a local HTML file from the resources folder. Now, this HTML file has Javascript inside it.

我的问题是,有一种方法来传递一个XCode变量到HTML文件我可以传递给HTML的Javascript函数的UIWebView。

My question is, is there a way to pass an XCode variable to the HTML file that gets loaded inside the UIWebView which I can pass to the Javascript function in the HTML.

非常感谢任何帮助或建议。

Thanks a lot for any help or suggestion.

推荐答案

您可以构造一个Javascript字符串,然后传入 -stringByEvaluatingJavaScriptFromString: ,例如

You can construct a Javascript string then pass into -stringByEvaluatingJavaScriptFromString:, e.g.

NSInteger u = get_integer_from_user();
NSString* script = [NSString stringWithFormat:@"call_your_function(%d);", u];
[webView stringByEvaluatingJavaScriptFromString:script];

这篇关于如何将XCode变量传递到资源文件夹中的HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆