Swift Update Label (with HTML content) takes 1min

馋奶兔 提交于 2019-11-28 08:41:46

Usual problem of updating UI in a secondary thread:

Your closure is obviously not running on the main thread, as the URL task is asynchronous. So updating the label on the closure will have to wait for the main thread to run its update loop. The way to fix it is to wrap the .text = call to force it to run on the main thread (which is where the UI stuff should run anyway):

        dispatch_async(dispatch_get_main_queue()) {
            self.LBoutput.text = "test6"
        }

In Swift 3:

DispatchQueue.main.async
{
    self.LBoutput.text = "test6"
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!