1

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

1
  • @Priya I ended up using ASIHTTPRequest, here, but it has been deprecated now, you can use Alamofire now Commented May 27, 2017 at 10:06

3 Answers 3

1

yes -- for each image that you want to download, you create a NSInvocationOperation which, when executed, will call the routine that downloads the image. The NSInvocationOperation is added to the queue, which is responsible for executing the NSInvocationOperation on it's own thread.

You only need one queue, but you need a new NSInvocationOperation for each download.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

Why not use blocks and Grand Central Dispatch to load these images? Check out this post and see if that will work for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.