开发者

NSOperation cancel problem

I have a problem. In my program I need to cancel operations (subclass NSOperation) in queue after clicking on button. But when I calling [queue cancelAllOperations] nothing开发者_Go百科 happens. The queue continue executing. All operations must be concurrent. What am I doing wrong?

 @interface SearchOperation : NSOperation 
{
TrueSearcherViewController *viewController;
SearchYouTube *you_search;
SearchGoogle *goo_search;
BOOL semafore;
}

- (id)initYoutubeTaskWithData:(SearchYouTube *) sy;
- (id)initGoogleTaskWithData:(SearchGoogle *) sg; 
- (void) beginYoutubeSearch:(SearchYouTube *) sy;
- (void) beginGoogleSearch:(SearchGoogle *) sg;
@end


#import "SearchOperation.h"

@implementation SearchOperation

- (void) start
{
if (semafore == YES)
    {
        [self beginYoutubeSearch:you_search];
    }
    else 
    {
        [self beginGoogleSearch:goo_search];
    }
}

- (id)initYoutubeTaskWithData:(SearchYouTube *) sy 
{
if (self = [super init])
{
    you_search = sy;
    semafore = YES;
}
return self;
}

- (id)initGoogleTaskWithData:(SearchGoogle *) sg
{
if (self = [super init])
{
    goo_search = sg;
    semafore = NO;
}
return self;
}


- (void) beginYoutubeSearch:(SearchYouTube *) sy
{
[sy runSearch];
}


- (void) beginGoogleSearch:(SearchGoogle *) sg
{
[sg runSearch];
}

- (void) dealloc
{
[super dealloc];
}

@end


You need to check in your code if your operation is cancelled to interrupt it with :

if(self.isCancelled){
return;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜