iphoneiosnsoperationqueuensinvocationoperation

loading multiple images from web using NSOperationQueue asynchronously


I have an array or urls which points to images present on the server. Now I want to display the images in a scrollview with 4 images on each row. I am thinking about using NSOperationQueue and NSInvocationOperation to download the images asynchronously. I am using following url as reference:
http://www.switchonthecode.com/tutorials/loading-images-asynchronously-on-iphone-using-nsinvocationoperation

But I am not sure how will I download multiple images. Do I have to run a for loop with multiple NSInvocationOperation objects and add it to NSOperationQueue object?

I am looking for any guidance to achieve my task.

EDIT: I have done following but NSOperationQueue is not able to call the NSInvocationOperation objects

NSOperationQueue *queue = [NSOperationQueue new];
for(int i = 0;i<rowcount;i++){
    for(int j =0; j<4;j++){
        UIButton *btnAlbum = [[UIButton alloc] initWithFrame:CGRectMake(x, y, 72, 72)];
        [btnAlbum setBackgroundImage:[UIImage imageNamed:@"placeHolder.png"] forState:UIControlStateNormal];
        btnAlbum.tag = count+100;
        //[btnAlbum addTarget:self action:@selector(viewAlbum:) forControlEvents:UIControlEventTouchUpInside];
        [scrlvw addSubview:btnAlbum];
        //[btnAlbum release];
        x = x + 80;
        count++;

        NSInvocationOperation *operation = [[NSInvocationOperation alloc] 
                                            initWithTarget:self
                                            selector:@selector(loadImage) 
                                            object:nil];

        [queue addOperation:operation]; 
        [operation release];
    }
    x = 0;
    y = y +80;
}

Thanks
Pankaj


Solution

  • ASIHTTPRequest came to rescue me and I was able to perform my task with ease.