UIImageView不会从URL iphone加载图像

时间:2013-06-27 07:20:03

标签: iphone uiimageview

我有imageView我想从网址加载图片,但它没有加载我正在使用以下代码

               pdfView.hidden=NO;
       webView.hidden=NO;
       pictureImageView.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);

        NSLog(@"Enterning in the ImageSection");

        NSString *ImageURL = fileName;
        NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
            pictureImageView.image = [UIImage imageWithData:imageData];         

而不是这个,如果我想从本地提供如下,那么它也不会在imageView中显示图像任何想法如何从网址加载图片谢谢

        pictureImageView.image=[UIImage imageNamed:@"starblue.png"];

4 个答案:

答案 0 :(得分:1)

首先设置该图像的帧,然后在pictureImageView

中添加图像后写入此行
            [self.view bringSubviewToFront:pictureImageView];

答案 1 :(得分:1)

代码看起来很好

要检查的事项

  1. 网址包含有效图片
  2. 设置ImageView正确设置框架然后添加图像
  3. UIImageView *pictureImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 50, 50)]; 然后做其余的

    这是同步图像加载,将阻止主线程活动。使用AFNetworking或AsynchImageview

    使用异步图像下载

答案 2 :(得分:1)

将此代码用于在网址中显示图片。

  NSString *image=[NSString stringWithFormat:@"Your URL"] stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
  NSLog(@"%@",image);
  NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:image]];
 Yourimageview=[UIImage imageWithData:imageData];

答案 3 :(得分:0)

 pictureImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgurl]]];