想知道我是否正确实施了以下方法,因为isCancelled
没有取消线程。我有一个正在缩放的图像,当它完成缩放时,调用此方法来更新图像。因此,当用户将手指从按钮上移开时,这被称为。如果他们在完成之前尝试再次按下按钮,我会调用cancelAllOperations
队列但它不起作用。甚至不确定 cancelAllOperations 是否触发标志,或者我是否需要继续调用它以获得结果。有人对此有任何见解吗?
- (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];
}