Tuesday, 20 August 2013

load images using SDWebImage in order

load images using SDWebImage in order

After a lot of reading and recommendations, I am trying to implement
SDWebImage framework in my app. I am able to download images from the
server but the issue is that as the images are different sizes, they are
not downloaded in the order that I call them (and would like them to be).
Here is the framework for reference: https://github.com/rs/SDWebImage
As you can see evidence of this from the print-line:
2013-08-20 11:11:01.785 Project[10785:c07] SD LOAD 1 array count = 1
2013-08-20 11:11:02.668 Project[10785:c07] SD LOAD 0 array count = 2
2013-08-20 11:11:02.946 Project[10785:c07] SD LOAD 3 array count = 3
2013-08-20 11:11:03.306 Project[10785:c07] SD LOAD 2 array count = 4
2013-08-20 11:11:03.862 Project[10785:c07] SD LOAD 4 array count = 5
2013-08-20 11:11:04.094 Project[10785:c07] SD LOAD 5 array count = 6
2013-08-20 11:11:04.793 Project[10785:c07] SD LOAD 6 array count = 7
2013-08-20 11:11:04.837 Project[10785:c07] SD LOAD 7 array count = 8
2013-08-20 11:11:05.046 Project[10785:c07] SD LOAD 8 array count = 9
2013-08-20 11:11:05.428 Project[10785:c07] SD LOAD 9 array count = 10
Below is my method:
-(void)sdWebLoadImages:(NSMutableArray*)imagesURLS{
[_loadedImages removeAllObjects];
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
_loadedImages = tempArray;
for (int i=0;i<imagesURLS.count;i++){
[_manager downloadWithURL:[imagesURLS objectAtIndex:i]
options:0
progress:^(NSUInteger receivedSize, long long
expectedSize)
{
// progression tracking code
}
completed:^(UIImage *image, NSError *error,
SDImageCacheType cacheType,BOOL finished)
{
if (image && finished)
{
[_loadedImages addObject:image];
NSLog(@"SD LOAD %i array count = %i",i,_loadedImages.count);
}
}];
}
}
How can I fix this (is it something in my for loop logic?). Also, I am
trying to cancel all the downloads when a button is clicked, and am using
[_manager cancelAll] but doesn't seem to work - any idea why?
Thanks fam!

No comments:

Post a Comment