- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Get notification when NSOperationQueue finishes all tasks
我遇到的问题与上面帖子中@porneL 发布的问题相同。我尝试了@NickForge 发布的解决方案(获得 57 票),但我显然做错了,因为它对我不起作用。这是问题设置和我的实现:
我需要在启动一组 Web 服务操作之前启动微调器,并在它们完成后停止微调器。 Web 服务通过共享的 AFHTTPClient
实例(AFNetworking 包的一部分)调用,该实例将它们添加到其 NSOperationQueue
。
我在 ViewController 中设置了一个观察器,从中开始加载数据。这是使用上面帖子的答案吗?我的 VC 中的实现如下所示:
在我的 ViewController 的 init
方法中:
//add WelcomeVC as an observer for AFHTTPClient dataloadOps notifications
[[[MyCustomAFHTTPClient sharedClient] operationQueue] addObserver:self forKeyPath:@"DataLoaderEvent" options:0 context:NULL];
在我的 ViewController 的 observeValueForKeyPath
方法中:
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if( (object == [[MyCustomAFHTTPClient sharedClient] operationQueue])
&& [keyPath isEqualToString:@"DataLoaderEvent"]) {
if ( [[[MyCustomAFHTTPClient sharedClient] operationQueue] operationCount] == 0) {
NSLog(@"EUREKA!!! QUEUE IS EMPTY! DATALOAD HAS COMPLETED!");
}
}
}
ViewController 的 observeValueForKeyPath
方法永远不会被调用!
如果您能帮助我完成这项工作,我将不胜感激,这样我就可以完成微调器的实现了。
最佳答案
operationQueue 是否有一个名为 DataLoaderEvent 的属性?通常情况下,我们会监视 NSOperationQueue 的“operationCount”属性。
“NSOperationQueue 类符合键值编码 (KVC) 和键值观察 (KVO)。您可以根据需要观察这些属性以控制应用程序的其他部分。您可以观察的属性包括以下内容:
操作 - 只读属性
operationCount - 只读属性"
关于ios - 以前发布的获取通知的解决方案(在 NSOperationQueue 上完成所有任务)对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14470052/
我在 crashlytics 中得到了一些我完全不明白的崩溃报告,这是崩溃线程的崩溃日志: 我没有找到任何关于我的代码的提示,它也不是可重现的或只发生在特定设备上的东西。根据 Crashlytics
我需要从 JSON 下载数据,并将数据分配给 NSOperationQueue 之外的 NSData。这是我的代码: -(void)parsingInfo { NSURL *url = [NS
我有一个应用程序,其中一个长时间运行的进程(> 1 分钟)被放置在 NSOperationQueue(队列 A)上。当队列 A 操作运行时,UI 完全响应,完全符合预期。 但是,我有一种用户可以执行的
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 1年前关闭。 Improve this
我有几个后台任务需要处理,同时仍保持 UI 响应。我开始走上创建和管理线程的道路,但很快就遇到了 NSOperations。听起来是一个更好的解决方案。 。 . 但是,我似乎无法获得对 NSOpera
我想知道释放 ivar NSOperationQueue 的正确方法是什么,以防它仍有一些操作正在运行,这种情况通常在用户突然退出应用程序时发生。在一些示例中,我看到使用了 waitUntilAllO
我正在努力解决这个问题,所以我的问题是: 当我像这样实例化 NSOperationQueue 时: NSOperationQueue * operationQueue = [[NSOperationQ
我第一次尝试基于 Swift/NSOperationQueue 的设计,我正在尝试找出如何维护跨队列的数据完整性。 我处于设计过程的早期阶段,但该架构可能会涉及一个队列(称为sensorQ),用于处理
我正在寻找一种重新排序 NSOperationQueue 的方法。 我可以取消所有操作并按照我想要的顺序将它们扔回去,但我希望有一些更干净的东西。有什么想法吗? 最佳答案 NSOperationQue
我是iPhone新手。在哪里可以找到NSOperationQueue和NSOperation的示例?NSOperationQueue和NSOperation与线程相比有什么优势? 谢谢 最佳答案 阅读
正如 NSOperationQueue 类引用所述:在 iOS 中,操作队列不使用 Grand Central Dispatch 来执行操作。它们为非并发操作创建单独的线程,并从当前线程启动并发操作。
我创建了一个NSOperationQueue子类,将maxConcurrentOperations设置为1,并将addOperation方法重写为以下内容: -(void)addOperation:(
我一直在使用 NSOperationQueue,但我遇到了非常奇怪的内存问题。我已经尝试将问题减少到最简单的问题,在这里我得到了: 在初始化中: _queue = [[NSOperationQueue
我最近开始学习 Swift 中的多线程,我想使用 NSOperationQueue 和 NSOperation 类尝试一些基本的多线程。 在 .swift 文件的全局范围内(在 Xcode 中的命令行
我的任务是清理项目中一些现有的 Swift 代码,这些代码刚刚转换为 Swift 3。但是,我不断看到这个对我来说看起来很可疑的代码。 OperationQueue().addOperation(so
我正在开发一个应用程序,该应用程序从使用 performSelectorInBackground 启动的单独线程中的循环调用 AudioServicesPlayAlertSound(kSystemSo
我在我的应用程序中使用了 NSOperation 子类,它将在单个操作中执行以下 4 个任务,我希望所有这 4 个任务都在后台线程上运行,所以我将其封装到单个 NSOperation 类,这样我就可以
我在暂停当前正在执行的任务时遇到问题,我尝试设置 NSOperationQueue setSuspended=YES 暂停和 setSuspended=NO恢复进程。 根据 apple docs我不能
我正在使用 NSOperationQueue 执行并发下载并插入到核心数据中。 下面是代码,我正在使用 if(nil==queue) { queue=[[NSOperationQueue al
我正在为 ios 进行调整(显示来自网络的一些图像),并且我正在尝试使用 NSOperationQueue。首先,我在主线程上运行了一些代码来看看它是什么样子。显示每个图像持续了 ±5 秒(UI 卡住
我是一名优秀的程序员,十分优秀!