Ios NSO操作取消错误

Ios NSO操作取消错误,ios,nsoperationqueue,Ios,Nsoperationqueue,在我当前的应用程序中,我正在子类化NSOperation。所有功能都按照我的要求运行良好。我可以取消操作并将新操作添加到我的操作队列中。除了成功之外,下面是我在控制台中找到的警告/错误语句: ***SubOperation 0x19ec1bd0 went isFinished=YES without being started by the queue it is in* 通过以上警告,我可以发现,我在开始之前取消了操作。因此,将来是否会发生内存泄漏或功能中断 警告的目的究竟是什么 到目前为止

在我当前的应用程序中,我正在子类化
NSOperation
。所有功能都按照我的要求运行良好。我可以取消操作并将新操作添加到我的操作队列中。除了成功之外,下面是我在控制台中找到的警告/错误语句:

***SubOperation 0x19ec1bd0 went isFinished=YES without being started by the queue it is in*
通过以上警告,我可以发现,我在开始之前取消了操作。因此,将来是否会发生内存泄漏或功能中断

警告的目的究竟是什么

到目前为止,功能正在发挥作用,没有中断,甚至我们仍然需要考虑警告并解决它?


您的所有建议都已打开。

然后首先检查操作是否在队列中

NSOperationQueue *queue = [[NSOperationQueue alloc] init];

NSOperation *operation = [[NSOperation alloc] init];

[queue addOperation:operation];

if([queue operations] containsObject:operation])
    NSLog(@"Operation is in the queue");
else
    NSLog(@"Operation is not in the queue");
或者,您可以迭代所有对象:

for(NSOperation *op in [queue operations])
    if (op==operation) {
        NSLog(@"Operation is in the queue");
    }
    else {
        NSLog(@"Operation is not in the queue");
    }

您有责任在子类化
NSOperation
时定期检查
[自取消]
,如果是
则退出该操作。操作队列无法(立即)取消已在运行的操作


如果覆盖
ready
,也必须覆盖
cancel
。抽象类中发生的情况是,当调用
cancel
时,它将操作设置为
ready
,以便队列可以调用
start
,方法检查取消标志,然后中止操作并设置
isFinished=YES
。然后操作队列解除锁定操作。你不能一个没有另一个。

谢谢你的快速回复。如果我在没有开始的情况下取消,会有什么影响吗?如果有人给出否决投票的理由,这将是一个很大的帮助。。。