• 카테고리

    질문 & 답변
  • 세부 분야

    모바일 앱 개발

  • 해결 여부

    미해결

weightTextField에서 엔터를 눌러도 키보드가 안내려가는 문제(활용앱 37강 07:00)

23.03.30 22:12 작성 조회수 212

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

 

위와 같이 입력을 했는데 두 텍스트필드를 입력하고 엔터를 누르면 밑 사진처럼 숫자 입력 키보드에서 한글 입력 키보드로 바뀌기만 할 뿐 키보드가 내려가지 않습니다.. 무엇이 문제일까요??

저 상태에서 화면 다른 부분을 터치했을 때 내려가긴 합니다.

 

Simulator Screen Shot - iPhone 14 - 2023-03-30 at 22.07.35.png

답변 1

답변을 작성해보세요.

0

네 안녕하세요, wldn6809님.

뷰 디드로드 코드에서 delegate설정이 잘 되어 있는 걸까요?

image
텍스트필드 엔터가 동작하지 않는다면.. 텍스트 필드 관련 대리자 설정이 안되어 있는 경우가 많아서요.

확인해보시고 말씀주세요!

wldn6809님의 프로필

wldn6809

질문자

2023.04.02

delegate 설정이 제대로 안되어 있었습니다ㅜ

수정하니까 잘 작동돼요!! 감사합니다 앨런님!!

강의 너무 잘 듣고 있어요~!!