2013-08-21 2 views
0

이미지를 배열에로드하는 데 SDWebImage를 사용합니다.캐싱 된 이미지를 다운로드하고 사용할 때 이미지를 배열로 순서대로로드

2013-08-20 17:45:51.318 img of index 0. Inserted at 0/1 with cacheType of 1 
2013-08-20 17:45:51.336 img of index 1. Inserted at 1/2 with cacheType of 1 
2013-08-20 17:45:51.350 img of index 2. Inserted at 2/3 with cacheType of 1 
2013-08-20 17:45:51.391 img of index 4. Inserted at 3/4 with cacheType of 1 
2013-08-20 17:45:51.402 img of index 6. Inserted at 4/5 with cacheType of 1 
2013-08-20 17:45:51.415 img of index 7. Inserted at 5/6 with cacheType of 1 
2013-08-20 17:45:51.419 img of index 8. Inserted at 6/7 with cacheType of 1 
2013-08-20 17:45:51.428 img of index 9. Inserted at 7/8 with cacheType of 1 
2013-08-20 17:45:54.982 img of index 3. Inserted at 8/9 with cacheType of 0 
2013-08-20 17:45:56.840 img of index 5. Inserted at 9/10 with cacheType of 0 

캐시 유형 : 나는이 이미지가 캐시 된 일부 이미지가 있기 때문에 그러나, 그들은 다운로드되고있는 이미지 앞에 배치되어, 내가 for 루프에서 그들을 호출 순서로로드해야

/** 
* The image wasn't available the SDWebImage caches, but was downloaded from the web. 
*/ 
SDImageCacheTypeNone = 0, 
/** 
* The image was obtained from the disk cache. 
*/ 
SDImageCacheTypeDisk, 
/** 
* The image was obtained from the memory cache. 
*/ 
SDImageCacheTypeMemory 

내 방법

//Web loading 
_manager = [SDWebImageManager sharedManager]; 
_manager.imageDownloader.maxConcurrentDownloads = 1; 

-(void)loadImages:(NSMutableArray*)imagesURLS{ 
    //_indexOfLastImageLoaded = 0; 
    [_loadedImages removeAllObjects]; 
    _loadedImages = [[NSMutableArray alloc]init];; 

    for (int i=0;i<imagesURLS.count;i++){ 
    [_manager downloadWithURL:[imagesURLS objectAtIndex:i] 
        options:0 
        progress:^(NSUInteger receivedSize, long long expectedSize) 
    { 
     //NSLog(@"%i out of %lli",receivedSize,expectedSize); 
    } 
        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType,BOOL finished) 
    { 
     if (image && finished) 
     { 
          [_loadedImages addObject:image]; 
      NSLog(@"img of index %i. Inserted at %i/%i with cacheType of %i",i,[_loadedImages indexOfObject:image],_loadedImages.count, cacheType); 

     } 
    }]; 
    } 
} 

I는 이와 같은 경우에 상기 어레이의 개수에 대해 확인 :

if(_loadedImages.count > _indexOfImageBeingDisplayed){ 
       NSLog(@"Top IV img loaded from array at index %i",_indexOfImageBeingDisplayed); 
       [_imagePreviewerTop setImage:[_loadedImages objectAtIndex:_indexOfImageBeingDisplayed]]; 
       [_imagePreviewerTop setFrame:_borderFrame]; 
      } 

이미지를 재정렬하면 사용자에게 표시하려고하는 정보가 엉망입니다. 나는 또한 "옵션"매개 변수를 변경하려고했지만 그 중 하나가 작동하지 않았다.

도움을 주시면 감사하겠습니다.

감사합니다.

답변

1

addObject 대신 replaceObjectAtIndex:WithObject을 사용하는 것이 좋습니다.

... 
if (image && finished) { 
    [_loadedImages replaceObjectAtIndex:i withObject:image]; 
} 
... 

이렇게하려면 먼저 자리 표시 자 값을 사용하여 배열을 초기화해야합니다.

_loadedImages = [NSMutableArray arrayWithCapacity:imagesURLS.count]; 
for (NSUInteger i = 0; i < imagesURLS.count; i++) { 
    [_loadedImages addObject:[NSNull null]; 
} 
+0

문제는 내가 검사하는 것은 _loadedImages.count와 비교되며 특정 인덱스가 개수보다 크면 어레이에서로드합니다. 그렇지 않으면 URL에서로드합니다. 만약 내가 다른 어떤 객체없이 인덱스 8에 객체를 삽입한다면, 그것은 내 배열 개수 9가되지 않을까? – royherma

+0

어디에서 계산합니까? –

+0

난 그냥 원래 게시물에 추가했습니다 – royherma

관련 문제