class ViewController: UIViewController, UITextFieldDelegate { //UITextFieldDelegate 추가 해주기
@IBOutlet weak var nameTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
nameTextField.delegate = self // delegate를 설정해주어야 키 이벤트와 통신이 됨
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func textFieldShouldReturn(textField: UITextField) -> Bool { // UITextFieldDelegate 추가하므로써 함수를 호출 할 수 있음
textField.resignFirstResponder() // 엔터(return)을 누르면 키보드가 내려가게 됨
return true
}
}
댓글
댓글 쓰기