以下代碼位於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