작성
·
296
0
extension ViewController: UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if Int(string) != nil || string == "" {
return true
}// 글자 입력을 허용
return false // 글자 입력을 허용하지 않음
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// 두개의 텍스트필드를 모두 종료 (키보드 내려가기)
if heightTextField.text != "", weightTextField.text != "" {
weightTextField.resignFirstResponder()
return true
// 두번째 텍스트필드로 넘어가도록
} else if heightTextField.text != "" {
weightTextField.becomeFirstResponder()
return true
}
return false
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
heightTextField.resignFirstResponder()
weightTextField.resignFirstResponder()
}
}
위와 같이 입력을 했는데 두 텍스트필드를 입력하고 엔터를 누르면 밑 사진처럼 숫자 입력 키보드에서 한글 입력 키보드로 바뀌기만 할 뿐 키보드가 내려가지 않습니다.. 무엇이 문제일까요??
저 상태에서 화면 다른 부분을 터치했을 때 내려가긴 합니다.
답변 1
0
네 안녕하세요, wldn6809님.
뷰 디드로드 코드에서 delegate설정이 잘 되어 있는 걸까요?
텍스트필드 엔터가 동작하지 않는다면.. 텍스트 필드 관련 대리자 설정이 안되어 있는 경우가 많아서요.
확인해보시고 말씀주세요!
delegate 설정이 제대로 안되어 있었습니다ㅜ
수정하니까 잘 작동돼요!! 감사합니다 앨런님!!
강의 너무 잘 듣고 있어요~!!