2017-08-10 7 views
0

私は、ユーザーが回答を入力できるようにするアプリケーションを作成しています。ユーザーが回答を入力した後にテキストを消すにはどうすればよいですか?間違っているか、私はテキストが消えたい。ユーザーが正しく回答した後にテキストフィールドを消去する方法は?

func textFieldDidChange(textField:UITextField) 
{ 
    if inputField?.text?.characters.count ?? 0 < 4 
    { 
     return 
    } 

    if let numbers_text = numbersLabel?.text, 
     let input_text  = inputField?.text, 
     let numbers   = Int(numbers_text), 
     let input   = Int(input_text) 
    { 
     print("Comparing: \(input_text) minus \(numbers_text) == \(input - numbers)") 

     if(input - numbers == 1111) 
     { 
      print("Correct!") 

      score += 1 

      showHUDWithAnswer(isRight: true) 
     } 
     else 
     { 
      print("Incorrect!") 

      score -= 1 

      showHUDWithAnswer(isRight: false) 
     } 
    } 

    setRandomNumberLabel() 
    updateScoreLabel() 
+1

多分、ユーザが自分のANSを送信したときに " "あなたはyourtextField.text =を設定することができます – koropok

+0

を"" = textField.textを試してみてください。 – luckyShubhra

答えて

0

ちょうど...テキストフィールドが隠されていますか?

inputField.resignFirstResponder() 
inputField.text = "" 
inputField.isHidden = true 
0
you can use textfield delegates to check what text is typed 

e.g. in viewDidload() { 
    textfield.delegate = self 
} 

then extend UIViewController with UITextFieldDelegate and use this 
function of delegate to compare text of textfield with your answer 

func textField(_ textField: UITextField, shouldChangeCharactersIn 
range: NSRange, replacementString string: String) -> Bool { 
    if textField.text == YOUR_ANSWER { 
     textField.text = nil 
     print(textField.text ?? "") 
    } 
    return true 
} 
関連する問題