Swift Update Label (with HTML content) takes 1min

前端 未结 2 708
北海茫月
北海茫月 2020-12-09 13:25

I got a small problem, let me start with the code

class ViewController: UIViewController {

@IBOutlet weak var LBoutput: UILabel!
@IBAction func BTclick(sen         


        
相关标签:
2条回答
  • 2020-12-09 13:49

    In Swift 3:

    DispatchQueue.main.async
    {
        self.LBoutput.text = "test6"
    }
    
    0 讨论(0)
  • 2020-12-09 14:11

    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"
            }
    
    0 讨论(0)
提交回复
热议问题