2011-07-05 15 views
2

私はウェブビューの背景に画像を表示しようとしていますが、内側に青色の長方形と質問マークがあります。私のコードはウェブビューで画像を表示する

NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n" 
            "<head> \n" 
            "<style type=\"text/css\"> \n" 
            "body {font-family:helvetica; font-size:12;}\n" 
            "h2 {font-family:Times new roman;color: #105870}" 
            "</style> \n" 
            "</head> \n" 
            "<body><img src=\"background.png\" /><h2>Nom station</h2>%@<h2>Adresse</h2>%@<h2>Tél</h2>%@<h2>Sens de circulation</h2>%@<h2>Voie</h2>%@<h2>Station de lavage</h2>%@<h2>Commerce</h2>%@<h2>Distance</h2>%@<h2>Types de carburants</h2>%@</body>\n" 
            "</html>",leNomDeLaStation,adresseDeLaStation,telDeLaStation,circulationDeLaStation,voieDeLaStation,lavageDeLaStation,commerceDeLaStation,distanceDeLaStation,typesDeCarburantsDeLaStation]; 
    [webView loadHTMLString:myDescriptionHTML baseURL:nil]; 

background.png以外のすべてのテキストが正しく表示されます。助けをありがとう:)

EDIT: 私はこれを試してみました:

NSString* basePath = [[NSBundle mainBundle] bundlePath]; 
    NSURL *url = [NSURL URLWithString:basePath]; 
    NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n" 
            "<head> \n" 
            "<style type=\"text/css\"> \n" 
            "body {font-family:helvetica; font-size:12;}\n" 
            "h2 {font-family:Times new roman;color: #105870}" 
            "</style> \n" 
            "</head> \n" 
            "<body><img src=\"background.png\" /><h2>Nom station</h2>%@<h2>Adresse</h2>%@<h2>Tél</h2>%@<h2>Sens de circulation</h2>%@<h2>Voie</h2>%@<h2>Station de lavage</h2>%@<h2>Commerce</h2>%@<h2>Distance</h2>%@<h2>Types de carburants</h2>%@</body>\n" 
            "</html>",leNomDeLaStation,adresseDeLaStation,telDeLaStation,circulationDeLaStation,voieDeLaStation,lavageDeLaStation,commerceDeLaStation,distanceDeLaStation,typesDeCarburantsDeLaStation]; 
    [webView loadHTMLString:myDescriptionHTML baseURL:url]; 

はいつも私が尋問マークを得た:(

+0

:私のコードはそれで問題を抱えているいずれかのために、このです fileURLWithPath:path方法を。 :) – Kjuly

答えて

0

私が忘れている、私の問題を解決:あなたは答えを受け入れるべき

NSString *path = [[NSBundle mainBundle] bundlePath]; 
    NSURL *baseURL = [NSURL fileURLWithPath:path]; 
    NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n" 
            "<head> \n" 
            "<style type=\"text/css\"> \n" 
            "body {font-family:helvetica; font-size:12;}\n" 
            "h2 {font-family:Times new roman;color: #105870}" 
            "</style> \n" 
            "</head> \n" 
            "<body><img src=\"background.png\" /><h2>Nom station</h2>%@<h2>Adresse</h2>%@<h2>Tél</h2>%@<h2>Sens de circulation</h2>%@<h2>Voie</h2>%@<h2>Station de lavage</h2>%@<h2>Commerce</h2>%@<h2>Distance</h2>%@<h2>Types de carburants</h2>%@</body>\n" 
            "</html>",leNomDeLaStation,adresseDeLaStation,telDeLaStation,circulationDeLaStation,voieDeLaStation,lavageDeLaStation,commerceDeLaStation,distanceDeLaStation,typesDeCarburantsDeLaStation]; 
    [webView loadHTMLString:myDescriptionHTML baseURL:baseURL]; 
+1

ちょっと、これは私が最初にあなたに提案したものでした! :-) – sergio

3

あなたは正しいbaseURL指定する必要があります。

[webView loadHTMLString:myDescriptionHTML baseURL:nil]; 

ウェブビューでは、「相対」URL( HTTPで始まらないもの:

NSString* basePath = [[NSBundle mainBundle] bundlePath]; 
[webView loadHTMLString:myDescriptionHTML baseURL:[NSURL fileURLWithPath:basePath]]; 

EDIT:あなたのプロジェクトのリソースでbackground.pngを含めて、ファイル名が正しいことをすることをダブルチェック//)

はこれを試してみてください。

+0

私は、私は必要がないと思う、私はフォーマットされたテキストを表示するためだけにWebビューを使用し、私はそれが私はpull 'nil'をナビゲートする必要はなかった – Malloc

+0

あなたはpngを表示しています:' sergio

+0

私はあなたの提案をしようとするが、私はいつも尋問マークを持って、画像は表示されません、私の編集を見てください:) – Malloc