• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to update UI from a background thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >How to update UI from a background thread (From: Dave <email@hidden>)

  • Prev by Date: Re: How to update UI from a background thread
  • Next by Date: Re: How to update UI from a background thread
  • Previous by thread: Re: How to update UI from a background thread
  • Next by thread: Re: How to update UI from a background thread
  • Index(es):
    • Date
    • Thread