"没有结果"当没有脸出现(斯威夫特) - 简单

时间:2016-01-12 00:16:02

标签: ios swift uiimageview boolean wikipedia

我已经创建了一个应用程序,您可以在其中输入知名人物并从维基百科中提取他们的面孔。是的,当您输入具有维基百科页面的名称时,一切正常。但是如果你输入其他没有结果的东西,我需要有一些东西可以说"没有结果"。我的代码在下面,但是"没有结果"即使没有结果,也永远不会被召唤。

 func textFieldShouldReturn(textField: UITextField) -> Bool {
    realLoadingLbl.alpha = 1

    textField.resignFirstResponder()
  faceImageView.alpha = 0


    self.realLoadingLbl.text = "Loading...Trying to Grab Photo..."



    if timerRunning == false{
        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: ("Counting"), userInfo: nil, repeats: true)
        timerRunning = true
    }





    if let textFieldContent = textField.text{
        do {
            try WikiFaceRec.faceForPerson(textFieldContent, size: CGSize(width: 200, height: 250), completion: {(image:UIImage?, imageFound:Bool!) -> ()  in
                if imageFound == true{
                    self.timerCount = 6
                    self.timerRunning = false
                   self.realLoadingLbl.alpha = 0
                    dispatch_async(dispatch_get_main_queue(), {() -> Void in
                        self.faceImageView.image = image
                        self.faceImageView.alpha = 1
                        WikiFaceRec.centerImageViewOnFace(self.faceImageView)
                    })
                    if imageFound == false{
                        self.faceImageView.alpha = 0
                        self.realLoadingLbl.text = "No Results Found. Check your spelling and try again."
                        print("NO RESULTS")

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

1 个答案:

答案 0 :(得分:1)

您的if imageFound = false声明中包含if imageFound = true声明。