【发布时间】:2014-09-11 12:28:53
【问题描述】:
我想知道当我点击导航栏中的后退按钮时停止异步任务的方法。我已经完成了这段代码,但它不起作用...... 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];
}
即使我暂停线程,它也不会停止执行,它会在后台继续运行。任何人请帮助我
【问题讨论】:
-
查看此链接。可能有帮助:stackoverflow.com/questions/6737044/…
-
另外,不要尝试释放默认通知中心。
标签: ios grand-central-dispatch dispatch