2013-06-27 86 views
1

我的ImageView我想从URL加载图像,但它没有加载我用下面的代码,而不是的UIImageView不从URL iphone加载图像

   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任何想法如何从URL加载图像感谢该图像的

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

imageUrl contains images? –

+0

你给frameImageView? – AkaMu

+0

bad code formatting .. – rptwsthi

回答

1

,第一组帧,然后写这行添加图像pictureImageView

+0

我已添加pictureImageView from IB –

+0

是的,但可能是您添加的一些视图,这就带来视图和您的pictureimageview不显示,所以首先设置框架后正确添加这个UIImage中的任何图像,在您的项目中可用,并添加我的上面的行,然后让我知道你得到了什么... :)我希望它对你有用... –

+1

感谢它基本上我没有连接插座错误,谢谢它的工作 –

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

代码看起来很好

检查事项

  1. 网址包含有效的图像
  2. 设置ImageView的页头是正确设置框,然后添加图像

UIImageView *pictureImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 50, 50)]; 然后做其余的

这是同步的图像加载,将阻塞主线程activities.Prefer使用使用AFNetworking或AsynchImageview

1

使用此代码URL中显示的图像异步镜像下载。

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