jim*_*bob 7 iphone xcode grand-central-dispatch ios
所以基本上我需要能够在块运行完成后运行segue.我有一个块,它可以执行一些JSON操作,我需要知道它何时运行完毕.
我有一个名为json_queue的队列.
jsonQueue = dispatch_queue_create("com.jaboston.jsonQueue", NULL);
Run Code Online (Sandbox Code Playgroud)
然后我有一个使用以下语法的dispatch_async块:
dispatch_async(jsonQueue, ^{
[self doSomeJSON];
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
});
Run Code Online (Sandbox Code Playgroud)
它不会让我执行这一行:"[self performSegueWithIdentifier:@"modaltomenu"sender:self];"
试图从主线程或Web线程以外的线程获取Web锁.这可能是从辅助线程调用UIKit的结果.现在崩溃......
我在哪里可以检查线程何时完成其脏工作,以便我可以调用segue?
谢谢你们可爱的人们.
PS:啤酒和ups,泰迪熊和鲜花给谁能帮助<3.
Joh*_*who 27
您应该只在主线程上调用UI方法.尝试在主队列上调度performSegueWithIdentifier:
dispatch_async(jsonQueue, ^{
[self doSomeJSON];
dispatch_sync(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
});
});
Run Code Online (Sandbox Code Playgroud)
dispatch_async(jsonQueue, ^{
[self doSomeJSON];
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
//Finished with async block
});
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12007 次 |
最近记录: |