使用如下方式试试
NSURL *baseURL = [NSURL fileURLWIthPath:[[NSBundle mainBundle] bundlePath]];
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSError *error;
NSString *html = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error: error];
if (!error) {
       [webView loadHTMLString:html baseURL:baseURL];
}else {
      NSLog(@"error:%@",error);
}

解决方案 »

  1.   

    断点跟踪到 html 变量, 查看根据html文件路径是否正确解析到html的内容。 如果html变量返回nil ,就会出现一片空白,什么也不会加载。返回nil的原因可以从html文件的编码上查查,是不是UTF8格式
      

  2.   

    可能是html的转义字符 %,要用双%%
      

  3.   

    断点跟踪到 html 变量,等于网页的源码(应该表示已正确解析了网页内容吧)。html文件的编码也是UTF8格式,可是为什么还是出现一片空白呢?
      

  4.   

    使用NSLog(@"html:%@",html); 
    显示如下:html:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head><body><p>弹弹弹弹弹弹弹弹弹</p>
    </body>
    </html>
    --------------------------
    请赐教!
      

  5.   

    这样是没有问题的。那你就应该从你的显示控件入手了。有没有正确定义webview的显示位置,有没有将webview添加到view.这些情况都一一查查。
      

  6.   

    用排除法
    一:将 url 部分替换成 http://www.baidu.com 
           看看能不能显示出来。
          如果显示不出来的话, 你的显示方式有问题。如果可以显示网页的话,那么就是读取部分有问题,可以换一种方式来显示看看。一个 webView 显示的方式有很多种的,你可以尝试一下。NSBundle* bundle = [NSBundle mainBundle];  
    NSString*  resPath = [bunder resourcePath];  
    NSString* filePath = [resPath stringByAppendPathComponent:@"test.html"];  
       
    [WebView loadHTMLString:[NSString stringWithContentsOfFile:filePath] baseURL:[NSURL fileURLWithPath:[bundle bundlePath]]];
      

  7.   

    增加了以下代码之后,加载本地文件正常显示了。    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        
        [self.view addSubview: webView];
        
    ViewController.m总的代码如下:
    - (void)viewDidLoad {
        [super viewDidLoad];    
        webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];   
        [self.view addSubview: webView];
       // get the model which is a html file for the webView
        NSString * htmlPath = [[NSBundle mainBundle] pathForResource:@"temp" ofType:@"html"];
        NSString * htmlCont = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
        // load the html file to webView
        [webView loadHTMLString:htmlCont baseURL:nil];
    }在此感谢各位热心的帮助。