如何获得NSOperationQueue的完成块,这里我想从所有操作的开始到结束旋转活动指示器。
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
// Set the max number of concurrent operations (threads)
[operationQueue setMaxConcurrentOperationCount:3];
[operationQueue addOperations:@[operation, operation1, operation3,...] waitUntilFinished:NO];
感谢。
答案 0 :(得分:7)
您需要实施KVO才能观察。
转到addDependency
进行操作,这将有助于您完成" isFinished键"操作,并解决所有依赖关系,它执行KVN。之后,您可以运行自旋活动指标的逻辑。你也可以写一个块。请检查以下代码:
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSBlockOperation *operationObj = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"Show your activity...");
}];
[operationObj setCompletionBlock:^{
NSLog(@"Operation has finished...");
}];
[queue addOperation: operationObj];
检查以下参考URL
Get notification when NSOperationQueue finishes all tasks
When will completionBlock be called for dependencies in NSOperation