我想知道当我单击导航栏中的“后退”按钮时停止异步任务的方法。我已经完成了这段代码,但是却无法正常工作... dispatch_group_t imageQueue = dispatch_group_create();
dispatch_group_async(imageQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
imagedata=[[NSMutableArray alloc]init];
for (int i=0; i<[imageURL count]; i++)
{
NSLog(@"clicked ");
[imagedata addObject:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[imageURL objectAtIndex:i]]]]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"Avatardownloaded" object:imagedata userInfo:nil];
}
});
在视线中消失...
-(void)viewDidDisappear:(BOOL)animated
{
dispatch_suspend(imageQueue);
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"Avatardownloaded" object:nil];
[[NSNotificationCenter defaultCenter]release];
[avatarimages release];
[imagedata release];
[imageURL release];
}
即使我暂停线程,它也不会停止执行,它的keepon在后台运行。任何人都可以帮助我
Grand Central Dispatch适用于即发即弃的任务。如果您要取消任务,我建议使用NSOperation
和NSOperationQueue
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句