我的问题是,当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 =“未找到结果。请检查拼写并重试。”是需要改变的部分。是的,再次“没有结果!!!”立即打印。
if imageFound == false{
self.faceImageView.alpha = 0
self.realLoadingLbl.text = "No Results Found. Check your spelling and try again."
print("NO RESULTS!!!!!")
}
你需要处理与imageFound==false
相似的true
案例的dispatch_async
案例:
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
}
}