【发布时间】:2015-01-08 21:08:24
【问题描述】:
我想将通过网络服务接收到的一些内容(动态)添加到现有的本地 HTML 文件中,然后在网络视图中显示。但我无法弄清楚如何将内容添加到本地 HTML 文件中。
提前致谢。
【问题讨论】:
-
您的意思是说您需要根据来自网络服务的结果构建 HTML?
我想将通过网络服务接收到的一些内容(动态)添加到现有的本地 HTML 文件中,然后在网络视图中显示。但我无法弄清楚如何将内容添加到本地 HTML 文件中。
提前致谢。
【问题讨论】:
你可以像这样使用 javaScript 传递值
NSURL *indexFileURL = [bundle URLForResource:@"name_of_your_local_html" withExtension:@"html"];
self.query1=[indexFileURL absoluteString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:indexFileURL];
[wbView loadRequest:request];
假设您的 HTML 中有一个键“myKey”
<td><span class="fieldVal" id="myKey"></span></td>
并像这样使用传递值
NSBundle *bundle = [NSBundle mainBundle];
NSURL *indexFileURL = [bundle URLForResource:@"name_of_your_local_html" withExtension:@"html"];
[wbView loadRequest:[NSURLRequest requestWithURL:indexFileURL]];
[wbView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('myKey').innerHTML='%@'",@"myValue"]];
【讨论】: