我对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