The text field is going to allow the user to use the keyboard on the iPhone and type in an input.
<aside>
π‘ Q: How to open keyboard in simulator? command + k
</aside>
Placeholder : ν°μ 미리보기 κΈμ
Text input traits λ₯Ό ν΅ν΄ μ λ ₯κ°μ λν μ€μ μ λ°κΏμμμ
It will allow our class, our ViewController, to manage the editing and validation of text and in a text-field
set text field delegate
class WeatherViewController: UIViewController, UITextFieldDelegate {
...
}
A set of optional methods to manage the editing and validation of text in a text field object.
ν μ€νΈ νλ κ°μ²΄μμ textλ₯Ό μμ νκ±°λ validation(?)μ κ΄λ¦¬νλ μ νμ μΈ ν¨μλ€μ λͺ¨μ
delegate μ μ
searchTextField.delegate = self
μΌλ ¨μ λ κ³Όμ μ ν μ€νΈ νλμμ μΌμ΄λλ μ¬μ©μμμ μνΈμμ©λ€ (ν°μΉ, μ λ ₯ λ±)μ μμν delegateμκ² μ λ¬μ νλ½ν΄μ£Όκ³ , ν΄λΉ delegateμ λ€μ΄μλ ν¨μλ€μ μ¬μ μν΄μ μ¬μ©ν μ μκ² (override) λ§λ€μ΄ μ£Όλ κ³Όμ
<aside> π‘ How to dismiss keyboard? textfield.endEditing
</aside>
Remember, the delegate is the one who is notified. By being the delegate of the text field, our view controller can be notified when the text field ends editing. Similar to how we got hold of textFieldShouldReturn,
//μ¬μ©μκ° ν€λ³΄λμ return keyλ₯Ό λλ μ λ, boolμ λ°ν
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
print("pressed the return button")
return true
}
delegate method νΈμΆ μμ