2012-10-30 3 views
2

이미지 URL이 포함 된 배열이 있는데, 그 URL을 사용하여 이미지보기를 만들려고합니다 (지금 for 루프 사용).URL 배열로 UIImageView를 채우는 방법은 무엇입니까?

하지만 난 생각을 못하고 있어요, 배열 희망의 URL을 사용하여 이미지 뷰를 만드는 방법을 일부는 명확합니다 당신은 imageNamed 대신 imageWithData를 사용해야이

int x = 0; 
for(int i = 0; i <imagearry.count; i ++){ 
NSDictionary *dict = [imagearry objectAtIndex:i]; 
NSLog(@"%@",[dict objectForKey:@"img_url"]); 
NSString *filePath [NSHomeDirectory()stringByAppendingPathComponent:@"/Library/Caches"]; 

    stringarry = [[imagearry objectAtIndex:i] objectForKey:@"img_url"]; 

    int x = 0; 

    imageView.image = [UIImage imageNamed:[stringarry objectAtIndex:0]]; 

    for(int i=0; i < [stringarry count]; i++) 
    { 

     UIImageView *img = [[UIImageView alloc] init]; 
     img.bounds = CGRectMake(10, 10, 50, 50); 
     img.frame = CGRectMake(5+x, 0, 160, 110); 
     NSLog(@"image: %@",[stringarry objectAtIndex:i]); 


     img.image = [UIImage imageNamed:[stringarry objectAtIndex:i]]; 
     [stringarry insertObject:img atIndex:i]; 
     [scrollView addSubview:[stringarry objectAtIndex:i]]; 

     x += 170; 
+0

무엇을 의미하는지 "내가 해당 URL과 이미지보기를 만들려면"는 무엇입니까? 모든 URL에 대해 ImageView를 만들려면 Three20 라이브러리의 TTImageView를 살펴보십시오. –

답변

0

UIImageView에는 URL의 이미지를 표시 할 수있는 속성이 없습니다. NSDATA 형식으로 다운로드 한 다음으로 변환해야 할 수 있습니다.UIImage. 대신 AsyncImageView를보고 AsyncImageView의 인스턴스를 배열에 저장하십시오.

확인이 링크 : AsyncImageView

+0

그것은 내가 생각하는 속성을 가지고 있습니다 .. UIImage * image = [UIImage imageWithData : [NSData dataWithContentsOfURL : [NSURL URLWithString : MyURL]]]]; –

+0

yes..true thats는 내가 대답 .. 그러나 UIImages가 배열에서 다운로드되지 않은 경우이 접근법은 동기 적이므로 기본 UI를 차단합니다 .Hind AsyncImageView 비동기식으로 계속 다운로드합니다 – AppleDelegate

+0

이미지가 디스크가 imageWithData 옵션이 더 좋을 때, 인터넷의 이미지가 AsyncImageView 인 경우. – jcesarmobile

0

:

NSURL * url = [NSURL fileURLWithPath:[filePath stringByAppendingPathComponent:[stringarry objectAtIndex:i]]]; 
[UIImage imageWithData:[NSData dataWithContentsOfURL:url]]; 
관련 문제