Xcode 更改标签文本时的延迟响应(Swift)
我的问题是,当imageFound==false时,它会立即打印出“No Results!!!”,但标签文本更改大约需要15秒。我不知道为什么这是滞后,但我需要帮助尝试我=把它放在5秒或更少的范围内 代码如下Xcode 更改标签文本时的延迟响应(Swift),xcode,swift,uiimageview,wikipedia,lag,Xcode,Swift,Uiimageview,Wikipedia,Lag,我的问题是,当imageFound==false时,它会立即打印出“No Results!!!”,但标签文本更改大约需要15秒。我不知道为什么这是滞后,但我需要帮助尝试我=把它放在5秒或更少的范围内 代码如下 if let textFieldContent = textField.text{ do { try WikiFaceRec.faceForPerson(textFieldContent, size: CGSize(width: 200, heig
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!!!!!")
}
在
dispatch\u 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
}
}
在
dispatch\u 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
}
}