Error about updating UI in background thread

How to fix the following error "bool _WebTryThreadLock(bool), 0xxxxxx: 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..."?

Cause: update ui in background thread.

Solution: update ui in main thread.

Generic use:

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // Do time-consuming task in background thread

	// Return back to main thread to update UI

        dispatch_sync(dispatch_get_main_queue(), ^{

            // Update UI

        });

    });

 

 


 

你可能感兴趣的:(background)