简体   繁体   English

从iOS上的后台线程更新UI

[英]Updating UI From a background thread on iOS

On iOS, its well documented that the UI should never be updated from a background thread. 在iOS上,有据可查的是,永远不要从后台线程更新UI。 Rather the main thread should be the sole interface to update the UI. 而是主线程应该是更新UI的唯一界面。 My Question is why? 我的问题是为什么?

Is it because UIControls are not thread safe and hence there is always the possibility of main thread updating the particular control whilst its being tinkered with in a background thread? 是不是因为UIControls不是线程安全的,所以主线程总是有可能在将特定控件放入后台线程时对其进行更新? Is my understanding right? 我的理解正确吗?

Thanks 谢谢

I think it has more to do with keeping the UI responsive, so iOS just prevents you from putting UI stuff in threads that aren't main. 我认为这与保持UI响应能力息息相关,因此iOS只能阻止您将UI内容放入不是主要的线程中。

You know you can use dispatch_asyn(dispatch_get_main_queue(), ) { //change UI here } from within a background thread to send your UI actions to the main thread. 您知道可以在后台线程中使用dispatch_asyn(dispatch_get_main_queue(), ) { //change UI here }将UI动作发送到主线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM