图像未加载到iphone的UIWebView中

图像未加载到iphone的UIWebView中,iphone,ios,image,uiwebview,Iphone,Ios,Image,Uiwebview,我有UIWebView,我想在其中加载图像,但它并没有在其中显示图像,我正在使用以下代码 pdfView.hidden=NO; webView.hidden=NO; pdfView.backgroundColor=[UIColor clearColor]; doneButton = [[UIBarButtonItem alloc]initWithTitle:@" Done " style:UIBarButtonItemStyleBordered target:

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

有没有办法加载此Web视图中来自服务器的文件名中的图像谢谢

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

NSURL *url = [NSURL fileURLWithPath:fileName];
UIImage *tempImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
imageView.image = tempImage;

另一种方法是动态创建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];
NSString*imageUrlString=@“您的url”;
NSString*yourText=@“这里有一些文本”;
NSString*htmlString=[NSString stringWithFormat:@“
%@”,imageUrlString,yourText]; [myWebView加载htmlString:htmlString基URL:nil];
我想你可以稍微收紧一下。不需要获取字符串路径并从中创建文件URL,只需向bundle请求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]];

我认为您的路径不正确。从服务器获取图像的真正路径是什么?这是服务器获取图像的路径检查一下,我想你应该检查一下你的文件名。路径是否与实际的url相同。而你给我的路径不起作用。所以可能是你的路径有问题,是否有必要在uiwebview中加载图像?所以你不认为这是图像url不正确吗?因为你给我的url不正确它在我的浏览器中不起作用。如果你只想显示图像,你能使用uiimageview而不是uiwebview吗?我有一个更简单的解决方案,用于AsyncImageView,它既不会在本地存储图像,也不会在处理过程中非常快。请告诉我,解决方案是否有一种方法可以检查url是否正常,或者不只是复制您的url并尝试粘贴在浏览器选项卡中…如果您可以在浏览器中看到该图像…那么它的工作正常..现在我认为唯一的问题是urlstring…不要担心,只要转到此链接,它将进一步帮助您