我對GCD很新,我不確定我是否做錯了什麼。我的代碼是這樣的:dispatch_async仍然阻止我的用戶界面
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if([manager updateRecord:foodRecord]) // this function will connect to a web server, and might take a few seconds. If I remove it, the UI will be smooth as butter
{
dispatch_async(dispatch_get_main_queue(), ^{
[cell expandAnimation]; // this function calls a series of UIView animateWithDuration to basically scale the cell and then call a reloadData when it's done
});
}
});
任何想法爲什麼它仍然會導致同步行爲?我嘗試使用GCD之前和之後似乎沒有區別。
這種「同步行爲」究竟是什麼?你是說在這個dispatch_async後面沒有一行代碼嗎?無論如何,這個問題並不在上面的代碼中。也許在'updateRecord'方法中。如WWDC 2012視頻[在iOS上構建併發用戶界面](https://developer.apple.com/videos/wwdc/2012/?id=211)中所示,您可以隨時使用「記錄等待線程」選項。 – Rob
管理器的-updateRecord方法是線程安全的嗎?如果不是這樣,你是否在同一個線程上實例化和訪問經理資源? – bteapot
請在'updateRecord'方法中分享你的代碼..似乎有一些問題。 – itsji10dra