Re: How to update UI from a background thread
Re: How to update UI from a background thread
- Subject: Re: How to update UI from a background thread
- From: Jens Alfke <email@hidden>
- Date: Wed, 21 Sep 2016 10:10:56 -0700
> On Sep 21, 2016, at 8:40 AM, Dave <email@hidden> wrote:
>
> How can I update my UI from a background thread?
You can’t literally do that. But you can schedule code to run on the main thread, and update the UI in that code. Use dispatch_async to schedule the UI-related code on the main thread/queue. Or if you’re feeling old-school, use -performSelectorOnMainThread:.
Even so, it’s a better design to decouple the UI-related code from the worker code. For instance you could have the worker code post a notification that the UI code can observe. Since the notification will get delivered on the worker thread, the UI code’s observer method should use the techniques above to tell itself to do the work on the main thread.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden