0

その中に画像をロードしたいUIWebViewがありますが、画像が表示されません次のコードを使用しています

     pdfView.hidden=NO;
    webView.hidden=NO;
    pdfView.backgroundColor=[UIColor clearColor];

    doneButton = [[UIBarButtonItem alloc]initWithTitle:@" Done " style:UIBarButtonItemStyleBordered target:self action:@selector(doneButtonClick)];            
    self.navigationItem.leftBarButtonItem =doneButton;


    webView.backgroundColor=[UIColor clearColor];


    NSLog(@"File Name is %@",fileName);

    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"png"];




    NSURL *url = [NSURL fileURLWithPath:fileName];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView setScalesPageToFit:YES];

    [webView loadRequest:request];      

このwebViewのサーバーから来るfileNameにあるこの画像をロードする方法はありますか

4

3 に答える 3

1

私が行くことができる他の方法は、動的にhtmlページを作成してUIWebViewにロードすることです:

NSString *imageUrlString = @"your url ";
NSString *yourText = @"Some text here";

NSString *htmlString = [NSString stringWithFormat:@"<img src='%@'/><br><b>%@</b>", imageUrlString, yourText];    
[myWebView loadHTMLString:htmlString baseURL:nil];
于 2013-06-20T10:29:07.860 に答える
0

これで少し絞れると思います。文字列パスを取得してそこからファイル URL を作成する代わりに、バンドルに URL を要求するだけです。

ファイル名にはすでにファイル拡張子が含まれており、実際には有効なファイル パス/URL が返されていないというのが私の推測です。デバッガーでステップスルーして確認してください。

// get the file resource URL
NSURL *url = [[NSBundle mainBundle] URLForResource: filename withExtension: @"png"];

// sanity check - did we get a valid URL?
NSAssert( url != nil && [url checkResourceIsReachableAndReturnError: NULL], @"oops - no resource!");

// load it
[webView loadRequest: [NSURLRequest requestWithURL:url]];
于 2013-06-20T16:48:55.580 に答える
-1

UIImageView だけを使用できないのはなぜですか? これは手作業で行われますが、次のようなものです。

NSURL *url = [NSURL fileURLWithPath:fileName];
UIImage *tempImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
imageView.image = tempImage;
于 2013-06-20T10:16:46.723 に答える