So basically I need to be able to run a segue after a block has finished running. I have a block which does some JSON stuff and I need to know when that has finished running.
I have a queue which I have called json_queue.
jsonQueue = dispatch_queue_create("com.jaboston.jsonQueue", NULL);
I then have a dispatch_async block with this syntax:
dispatch_async(jsonQueue, ^{
[self doSomeJSON];
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
});
It wont let me perform the line: "[self performSegueWithIdentifier:@"modaltomenu" sender:self];"
Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
Where can I check to find out when the thread has done its dirty work so i can call the segue?
Thankyou lovely people.
PS: beer and ups and teddy bears and flowers to whoever can help <3.
When using dispatch_async for a background queue, GCD (Grand Central Dispatch) will ask the kernel for a thread, where the kernel either creates one, picks an idle thread, or waits for one to become idle. These threads, once created, live in the thread pool.
Submits a block for asynchronous execution on a dispatch queue and returns immediately.
Submits a block object for execution and returns after that block finishes executing. iOS 4.0+ iPadOS 4.0+ macOS 10.6+ Mac Catalyst 13.1+ tvOS 9.0+ watchOS 2.0+
You should call UI methods on main thread only. Try to dispatch performSegueWithIdentifier: on main queue:
dispatch_async(jsonQueue, ^{
[self doSomeJSON];
dispatch_sync(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With