NSOperation在完成任务后没有从NSOperationQueue中删除?

时间:2014-04-11 05:14:19

标签: ios nsoperation nsoperationqueue

您好我正在使用Xcode 5+和iOS 7+,并实施NSOperationQueue。我创建了NSOpeartion的子类,并说我在NSOperationQueue中添加了50+操作。在NSOperation的启动方法中重写了isExecuting和isFinished -

-(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次操作)没有得到执行主方法。请给我一些关于何时出现这个问题的澄清。

谢谢

1 个答案:

答案 0 :(得分:3)

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

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