以下代码位于cellForRowAtIndexPath
内。使用块异步下载
1)我需要以某种方式修改此代码,取消下载或当viewDissapears时的块。我想,我应该首先初始化.h
文件中的一个块,然后在cellForRowAtIndexPath
中使用它,然后在viewDidDissapear
时将其设置为零。 (我不确定这种方法是否正确)。有人可以帮我编辑这段代码吗?
注意:当用户在特定的视图上,以及下面的代码下载一些图像时,用户决定移动到另一个视图。然后我想取消下载在viewDidDissapear
方法
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
NSData *image = // I will be downloading an URL here
//this will set the image when loading is finished
dispatch_async(dispatch_get_main_queue(), ^{
// I will be displaying the Downloaded image here
});
});
这是使用ASIHTTPRequest? – shajem 2012-02-11 19:11:39
我不知道那是什么。看代码,你可以看到它的用途。这是一个完整的工作项目;所有的代码都在那里。没有技巧。 – matt 2012-02-11 20:49:44