2013-06-20 56 views
0

我有一个UIWebView我想在加载图像,但它并没有显示它像我用下面的代码图片无法在UIWebView中加载iphone

 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谢谢

+0

你的路径是我认为不正确。你从服务器获取图像的真正路径是什么? –

+0

http://celeritas-solutions.com/pah_brd_v1/productivo/pro/imageName.png这是服务器获取图像的路径 –

+0

检查了这一点http://iphonedevsdk.com/forum/iphone-sdk-development/1937- uiwebview-displays-image-from-resource-file.html – iCoder

回答

0

为什么你不能只使用UIImageView?这是手工完成的,但类似的;

NSURL *url = [NSURL fileURLWithPath:fileName]; 
UIImage *tempImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]]; 
imageView.image = tempImage; 
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]; 
+0

它显示了一些文字和它显示的图像?这个标志 –

+0

所以你不认为它的图像网址是不正确的吗?因为你的网址给了我它在我的浏览器不工作 –

+0

该网址与我合作我已经在浏览器上检查 –

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]];