在UIWebvView中加载名为'index.html?mod = eurt'的html文件

时间:2013-12-03 21:12:39

标签: ios uiwebview

首先让我说我知道如何加载html文件,但我需要加载 index.html?mod = eurt 。因此文件本身称为 index.html ,但我需要在最后加载?mod = eurt 。 (html文件在不同的应用程序之间共享,并且更改“?mod = X”,将告诉文件到底要做什么。

问题是,我无法弄清楚如何通过我将html加载到webview中的方式来实现这一点(我在iOS开发中相当新,所以可能存在一种我不知道的简单方法)。这是我到目前为止加载本地html文件的原因:

NSString *htmlFile=[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"
                       inDirectory:nil];

NSString *htmlString=[NSString stringWithContentsOfFile:htmlFile 
                       encoding:NSUTF8StringEncoding error:nil];

[webView loadHtmlString:htmlString baseURl:nil];

我尝试将ofType:@"html"更改为ofType:@"html?mod=eurt",但我并不希望这样做有效,但事实并非如此。

我来自Android的土地,我只是webView.loadUrl("file:///android_asset/index.html?mod=eurt");

在iOS中必须有一种简单的方法,对吗?

1 个答案:

答案 0 :(得分:0)

你可以做这样的事情

NSString* bundlePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString* strUrl = [[urlToLoad absoluteString] stringByAppendingString:@"?mod=eurt"];
NSURL* urlToLoad = [NSURL URLWithString:strUrl];
[webView loadRequest:[NSURLRequest requestWithURL:urlToLoad]];