ios - 完成任务后 NSOperation 未从 NSOperationQueue 中删除?

标签 ios nsoperation nsoperationqueue

嗨,我正在使用 Xcode 5+ 和 iOS 7+ ,并实现 NSOperationQueue。我创建了 NSOpeartion 的子类,并说我有 50 多个操作添加到 NSOperationQueue 中。 isExecuting 和 isFinished 在 NSOperation 的 start 方法中被重写 -

-(void)start{

   // soeme code is here 

   [self willChangeValueForKey:@"isExecuting"];
  _isExecuting = YES;
  [self didChangeValueForKey:@"isExecuting"];

  [self willChangeValueForKey:@"isFinished"];
  _ isFinished = NO;
  [self didChangeValueForKey:@"isFinished"];
}

完成任务后,我编写此代码

 [self willChangeValueForKey:@"isExecuting"];
  _isExecuting = NO;
  [self didChangeValueForKey:@"isExecuting"];

  [self willChangeValueForKey:@"isFinished"];
  _ isFinished = YES;
  [self didChangeValueForKey:@"isFinished"];

MaxConcurrentOperationCount 为 2。但是在完成 2 个操作后,下一个操作(第 3 个操作)不会执行 main 方法。请给我一些有关此问题何时出现的说明。

谢谢

最佳答案

启动时,您应该将 isExecuting 设置为 YES,但根本不应该设置 isFinished,尤其不要设置为 YES.

当你的异步操作完成后,你需要将isExecuting设置为NO,而不是YES,并且你需要设置 isFinishedYES,但您正在第二次设置 isExecuting

关于ios - 完成任务后 NSOperation 未从 NSOperationQueue 中删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23004031/

相关文章:

ios - 从不同的线程/ session 更新 Swift 中的 Realm 对象

iphone - 更改 UILabel 颜色动画

ios - NSOperationQueue 队列中当前操作的限制数量是多少

swift - Moya - 使用 NSOperation 链式请求

ios - Azure Blob 存储文件路径

ios - Iphone - 关于应用拒绝指南的说明

ios - NSOperation 子类性能或泄漏

ios - NSOperationQueue 不限制并发操作

macos - 通过在主队列上执行的 block 更新 NSProgressIndicator 时出现 CoreAnimation 警告

ios - 我们可以在 iOS 中创建多少个 NSOperationQueue?