Here is my code:
#ifdef DEBUG
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"JSON Parsing Error" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
#endif
This code is executed in a background thread (responsible for parsing), and the error only happens every other time. Any idea on what is the problem here?
Dont mess with the UI from the background thread. Create a method and call that method on the main thread:
[someObject performSelectorOnMainThread:@selector(showDebug:)
withObject:@"JSON Parsing Error"
waitUntilDone:YES];
You shouldn't execute UI code in separate thread.
If your application has a graphical user interface, it is recommended that you receive user-related events and initiate interface updates from your application’s main thread. This approach helps avoid synchronization issues associated with handling user events and drawing window content. Some frameworks, such as Cocoa, generally require this behavior, but even for those that do not, keeping this behavior on the main thread has the advantage of simplifying the logic for managing your user interface.
Threads and Your User Interface
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