2013-06-27 87 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]; 
相關問題