如何获取 NSOperationQueue 的完成块 [英] How to get completion block of NSOperationQueue

查看:91
本文介绍了如何获取 NSOperationQueue 的完成块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取 NSOperationQueue 的完成块,这里我想从所有操作的开始到结束旋转活动指示器.

How to get completion block of NSOperationQueue, here I want to spin activity indicator from start to end of all operation.

NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
// Set the max number of concurrent operations (threads)
[operationQueue setMaxConcurrentOperationCount:3];
[operationQueue addOperations:@[operation, operation1, operation3,...] waitUntilFinished:NO];

谢谢.

推荐答案

需要实现KVO来观察.

You need to implement KVO to observe.

在操作上寻找addDependency,这将帮助您找到操作的isFinished key",并解决所有依赖项,它执行KVN.之后,您可以运行旋转活动指示器的逻辑.你也可以写一个块.检查以下代码:

Go for addDependency on operation which will help you to "isFinished key" of the operation, and all dependency are resolved it performs KVN. After that you can run your logic of spin activity indicator. Also you can write a block as well. Check the following code:

NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSBlockOperation *operationObj = [NSBlockOperation blockOperationWithBlock:^{
    NSLog(@"Show your activity...");
}];

[operationObj setCompletionBlock:^{
    NSLog(@"Operation has finished...");
}];

[queue addOperation: operationObj];

检查以下参考网址

当 NSOperationQueue 完成所有任务时收到通知

NSOperation 中的依赖何时会调用completionBlock

这篇关于如何获取 NSOperationQueue 的完成块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆