如何检查dispatch_async块是否已经完成运行
所以基本上我需要能够在一个块完成运行后运行一个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];”
尝试从主线程或Web线程以外的线程获取Weblocking。 这可能是从辅助线程调用UIKit的结果。 现在崩溃…
我在哪里可以检查发现什么时候线程已经完成了它的肮脏的工作,所以我可以打电话给赛格?
谢谢可爱的人。
PS:啤酒和ups,泰迪熊和花朵,谁可以帮助<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 }); });