0

UIWebViewURLから画像をロードするときに遅延の問題があります。

私のコードには、ローカルのhtmlファイルをロードする行があります:

NSBundle *thisBundle = [NSBundle mainBundle];
NSString *path = [thisBundle pathForResource:@"detail" ofType:@"html"];
NSString *html = [NSString stringWithContentsOfFile:path];
NSString *htmlString = [NSString stringWithFormat:html, imageURL];
[webView loadHTMLString:htmlString baseURL:nil];

私のdetail.htmlファイルの行の1つ:

<img src="%@" height="100%" alt="…"></img>

ボタンを押して UIWebView に移動すると、最初は白で、数秒後に画像とテキストが表示されます。URLから画像を読み込むのに時間がかかるのは承知していますが、最初にテキストを表示し、次に画像の読み込みを待つことは可能ですか??

一般的に私は考えています:プッシュボタン - >移動UIWebView- >テキストを表示 - >ロード時に画像を表示

4

2 に答える 2

0

マーティンHの助けを借りて、私はなんとか問題を解決することができました。

最初にlocal.htmlファイルに、次の<head>セクションを追加しました。

<script type="text/javascript">
    function loadImage(imageSource) {
         document.getElementById("picture").src=imageSource;
    }
</script>

次の<body>セクション:

<img src="" style="border: none;" id="picture">

次に、UIViewControllerにデリゲートメソッドを追加しました。

- (void) webViewDidFinishLoad:(UIWebView *)web {
    [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"loadImage('http://example.com/image.jpg')"]];
}
于 2012-06-13T07:14:41.067 に答える