![](/img/trans.png)
[英]How can i download photos by order of cells in UITableView with dispatch_async?
[英]How can I be notified when a dispatch_async task is complete?
我有一個像這樣的異步任務:
dispatch_async(dispatch_get_main_queue(), ^{
myAsyncMethodsHere;
});
有沒有辦法在后台任務完成時得到通知?
或者在完成后調用方法?
我已經閱讀了文檔並查看了dispatch_after,但似乎更多的設計是在一段時間后調度該方法。
謝謝您的幫助。
來自文檔:
完成的回電
完成回調可以通過對dispatch_async()函數的嵌套調用來完成。 重要的是要記住在第一次調用dispatch_async()之前保留目標隊列,並在完成回調結束時釋放該隊列,以確保在完成回調掛起時不釋放目標隊列。 例如:
void
async_read(object_t obj,
void *where, size_t bytes,
dispatch_queue_t destination_queue,
void (^reply_block)(ssize_t r, int err))
{
// There are better ways of doing async I/O.
// This is just an example of nested blocks.
dispatch_retain(destination_queue);
dispatch_async(obj->queue, ^{
ssize_t r = read(obj->fd, where, bytes);
int err = errno;
dispatch_async(destination_queue, ^{
reply_block(r, err);
});
dispatch_release(destination_queue);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.