NSOperation取消问题
我有一个问题。在我的程序中,我需要在单击按钮后取消队列中的操作(NSOperation 子类)。但是当我调用 [queue cancelAllOperations] 时什么也没有发生。队列继续执行。所有操作必须并发。我做错了什么?
@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
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的操作被取消,您需要签入代码以中断它:
You need to check in your code if your operation is cancelled to interrupt it with :