嗨,我正在使用 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
,并且你需要设置 isFinished
为 YES
,但您正在第二次设置 isExecuting
。
关于ios - 完成任务后 NSOperation 未从 NSOperationQueue 中删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23004031/