2013-07-14 84 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];