[self.operationsQueue waitUntilAllOperationsAreFinished];
[self.operationsQueue cancelAllOperations];
è¿™æ— æ³•è¾¾åˆ°æˆ‘çš„ç›®çš„ã€‚
如何å–消NSOperationsQueue
ä¸çš„所有æ“作并从队列ä¸åˆ 除所有æ“作?
ç”案 0 :(得分:0)
您ä¸éœ€è¦[self.operationsQueue waitUntilAllOperationsAreFinished]
。
[self.operationsQueue cancelAllOperations]
åªå¯¹é˜Ÿåˆ—ä¸çš„所有æ“作设置isCancelled = YES
,由æ“作本身决定对æ¤åšå‡ºå应。
æ‰€ä»¥ä½ éœ€è¦åšçš„就是在self.isCancelled
è¿è¡Œæ—¶å®šæœŸæ£€æŸ¥ã€‚{/ p>
- (void)main
{
if (self.isCancelled) {
return;
}
// Do some work
if (self.isCancelled) {
return;
}
// Do some more work
}