2013-07-14 85 views
0

我在S/O上搜索,没有答案已经应用到我的代码,所以我假设我的代码中缺少的东西。UIWebView不显示HTML

我加了一个UIWebView使用Interface Builder称为showAbout

我宣布这里有一个IBOutlet伊娃:

@interface About : UIViewController<UIWebViewDelegate> 
{ 
    IBOutlet UIWebView *showAbout; 
} 


@property (nonatomic, retain) IBOutlet UIWebView *showAbout; 

我证实了InterfaceBuilder事实上确实有它设置一个出口。

这里是我如何设置它在about.m

showAbout.scalesPageToFit = YES; 
    NSString *thePath = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"]; 
    if (thePath) { 
     NSData *aboutData = [NSData dataWithContentsOfFile:thePath]; 
     [showAbout loadData:aboutData MIMEType:@"application/html" 
         textEncodingName:@"utf-8" baseURL:nil]; 

的UIWebView中不显示,我已经添加到项目中我的HTML页面。

任何想法...

+0

http://stackoverflow.com/questions/6263289/accesing-a-file-using-nsbundle-mainbundle-pathforresource-oftypeindirectory可能是你的问题。 – 2013-07-14 20:24:09

+1

是关于数据无? –

+0

@PaulCezanne,我没有设置从我的Mac这个赏金...将今晚检查和建议。 – logixologist

回答

1

正确MIME type for HTMLtext/html,不application/html .h文件中,所以你应该使用它作为MIMEType参数。

另外,您还可以在你的NSData对象转换为NSString和使用的UIWebViewloadHTMLString:baseURL:方法。

3

可能最好是使用NSString和负荷的html文件如下:

ViewController.h文件

@property (retain, nonatomic) IBOutlet UIWebView *webView; 

确保财产连接到XBIB/StoryBoard中的webView

ViewController.m文件

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"]; 
    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil]; 
    [self.webView loadHTMLString:htmlString baseURL:nil]; 
1

在您需要的初始网页视图的出口

IBOutlet UIWebView *_wvSetting;    

在.m文件

 NSString htmlContent = nil; 
     htmlContent = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"] encoding:NSUTF8StringEncoding error:nil]; 
     [_wvSetting loadHTMLString:htmlContent baseURL:nil];