Changing UILabel text has delay, but why?

后端 未结 2 1990
囚心锁ツ
囚心锁ツ 2021-01-22 15:08

in my app I want to set the text of an UILabel. The text comes from a JSON-object. I add my UILabel to my storyboard, set the IBOutlet and

2条回答
  •  天命终不由人
    2021-01-22 16:09

    Like what Rob stated in the comment, all UI changes need to be done on the main thread. I haven't implemented it in Swift yet, but the Objective-C and what I'm assuming would be the Swift is below...

    Objective-C

    dispatch_async(dispatch_get_main_queue(), ^{
        self.label_news.text = resp.NewsText;
    });
    

    Swift:

    dispatch_async(dispatch_get_main_queue()) {
        self.label_news.text = resp.NewsText;
    }
    

提交回复
热议问题