2009-11-11 8 views
0

Voici mon code:Impossible de charger le fichier html à WebView

NSString * chemin1 = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @ "NewSouthWales.html"];

NSURL *pageURL = [NSURL fileURLWithPath:path1]; 
//URL Requst Object 
NSURLRequest *requestObj = [NSURLRequest requestWithURL:pageURL]; 

//Load the request in the UIWebView. 
[self.webView loadRequest:requestObj]; 

Je reçois dans mon sortie WebView comme: comme

........

au lieu de me donner une bonne apparence de ce fichier, il montre code source de la page.

S'il vous plaît aider ... Merci à l'avance

+0

Je chargement de ce fichier html à partir des ressources. – Nic

Répondre

0

D'abord préfèrent pathForRessource ofType

pathNSString * chemin1 = [[NSBundle mainBundle] pathForResource: @ "NEWSOUTHWALES" OfType: @ "html"];

Et puis, si le fichier est local, pourquoi envoyer une requête? utiliser Just:

NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil]; 
[self.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]]; 
0
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"NewSouthWales" ofType:@"html"]; 
    NSURL *baseurl = [NSURL fileURLWithPath:path1]; 

    NSData *pathData = [NSData dataWithContentsOfFile:path1]; 
//Check first if the file path's data is captured. if true, load the html on the web view 

    if (pathData) { 
     [webView loadData:pathData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseurl]; 
    } 
Questions connexes