更改标签文本时延迟响应 (Swift)

Delayed response when changing label text (Swift)

我的问题是,当 imageFound == false 时,它​​会立即打印出 "No Results!!!",但标签文本需要 15 秒才能更改。我不知道为什么这会滞后,但我需要帮助尝试 i= 将其降低到 5 秒或更短的范围内。

代码如下...

if let textFieldContent = textField.text{
        do {

            try WikiFaceRec.faceForPerson(textFieldContent, size: CGSize(width: 200, height: 250), completion: {(image:UIImage?, imageFound:Bool!) -> ()  in
                if imageFound == false{
                    self.faceImageView.alpha = 0
                    self.realLoadingLbl.text = "No Results Found. Check your spelling and try again."
                    print("NO RESULTS!!!!!")

                }
                if imageFound == true{
                   self.realLoadingLbl.alpha = 0
                    dispatch_async(dispatch_get_main_queue(), {() -> Void in
                        self.faceImageView.image = image

                        self.faceImageView.alpha = 1
                        WikiFaceRec.centerImageViewOnFace(self.faceImageView)
                    })

                }
            })
        } catch WikiFaceRec.WikiFaceError.CouldNotDownloadImage {
            print("Wikipedia not currently open")

        } catch {
            print("error")
            self.faceImageView.alpha = 0
            self.realLoadingLbl.text = "No Results Found. Check your spelling and try again."
            print("NO RESULTS")
        }
    }
    return true
}

下面带有 self.realLoadingLbl.text = "No Results Found. Check your spelling and try again." 的代码是需要修改的部分。是的,再次立即打印 "NO RESULTS!!!"。

if imageFound == false{
    self.faceImageView.alpha = 0
    self.realLoadingLbl.text = "No Results Found. Check your spelling and try again."
    print("NO RESULTS!!!!!")
}

您必须根据 dispatch_async 处理类似于 true 案例的 imageFound==false 案例:

if !imageFound {
    dispatch_async(dispatch_get_main_queue()) {
        self.faceImageView.alpha = 0
        self.realLoadingLbl.text = "No Results Found. Check your spelling and try again."
        print("NO RESULTS!!!!!")
        self.faceImageView.alpha = 0                      
    }
}