![](/img/trans.png)
[英]How to check dispatch_async get called or not earlier for same operation
[英]how to check an dispatch_async block has finished running
因此,基本上,我需要能够在块完成运行之后运行segue。 我有一个执行一些JSON内容的块,我需要知道何时完成运行。
我有一个名为json_queue的队列。
jsonQueue = dispatch_queue_create("com.jaboston.jsonQueue", NULL);
然后,我有一个使用以下语法的dispatch_async块:
dispatch_async(jsonQueue, ^{
[self doSomeJSON];
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
});
它不会让我执行以下行:“ [self performSegueWithIdentifier:@” modaltomenu“ sender:self];”
试图从主线程或网络线程以外的其他线程获取网络锁。 这可能是从辅助线程调用UIKit的结果。 现在崩溃了...
我在哪里可以检查线程何时完成其肮脏的工作,以便可以调用segue?
谢谢可爱的人。
PS:啤酒和大起大落,泰迪熊和鲜花对任何能够帮助我们的人<3。
您应该仅在主线程上调用UI方法。 尝试在主队列上分派performSegueWithIdentifier:
dispatch_async(jsonQueue, ^{
[self doSomeJSON];
dispatch_sync(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
});
});
dispatch_async(jsonQueue, ^{
[self doSomeJSON];
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
//Finished with async block
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.