Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 更改标签文本时的延迟响应(Swift)_Xcode_Swift_Uiimageview_Wikipedia_Lag - Fatal编程技术网

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

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

我的问题是,当imageFound==false时,它会立即打印出“No Results!!!”,但标签文本更改大约需要15秒。我不知道为什么这是滞后,但我需要帮助尝试我=把它放在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!!!!!")
}

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                      
    }
}