想知道如果我正确地执行下面的方法,因为isCancelled
不取消线程。我有一个缩放的图像,当缩放完成后,会调用此方法更新图像。所以当用户将他们的手指从按钮上移开时,这就是所谓的。如果他们在完成之前尝试再次按下按钮,我会在队列上呼叫cancelAllOperations
,但它不起作用。甚至不知道如果cancelAllOperations触发一个标志,或者如果我需要继续调用它来获得结果。任何人都有这方面的见解?如何取消NSOperationQueue
- (void) refreshImage
{
NSBlockOperation *operation = [[NSBlockOperation alloc] init];
__unsafe_unretained NSBlockOperation *weakOperation = operation;
[operation addExecutionBlock:
^{
UIImage *image = [[self.graphicLayer imageForSize:self.size] retain];
if (![weakOperation isCancelled])
{
[[NSOperationQueue mainQueue] addOperationWithBlock:
^{
self.image = image;
[image release];
}];
}
else
{
[image release];
return;
}
}];
[self.queue addOperation: operation];
[operation release];
}
确定在执行if(![weakOperation isCancelled])之前调用'cancelAllOperations'吗? – iDev
我真的不知道是诚实的LOL,我试图弄清楚的事情之一@ACB –
把NSLog语句,并检查哪一个是先调用。 – iDev