views:

65

answers:

2

I m using NSoperationQueue for load song from server.

This code execute when click on diff-diff buttons.

NSOperationQueue *queue;

NSInvocationOperation *operation = [[NSInvocationOperation alloc]

initWithTarget:self selector:@selector(loadImage)object:nil];

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

[queue addOperation:operation]; 

Problem is that when user click ie.Rama.aac then loading continue in this duration if he click krishna.aac then this process also goes into that queue.and conflicting is there.

user is finally requesting for krishna but in result first download rama.aac then krishna.aac.

I m using [queue cancelAllOperations] but it not works.

How i solve this?

+1  A: 

If I'm not mistaken using NSOperations to load data from a network is not advised. You should use the asynchronous loading NSURLConnection provides.

Yannick Compernol
Oh Yes,I m using NSURlConnection for loading data and NsOperationQueue is only for process management.
Please tell me how to solve my problem
Yannick: do you have a reference for that recommendation? In certain cases, using NSOperation in combination with synchronous downloads can be a great solution, IMHO. But indeed, you have more control if you use NSURLConnection.
Philippe Leybaert
Philippe: I don't have any written reference of that. But that's what I was told by one of the Apple Technology Evangelists at the iPhone Tech Talk in Paris last year.
Yannick Compernol
+1  A: 

Implement your own NSOperation subclass. NSOperation has isCancelled property set when cancelAllOperations is called on the queue.

TheBlack