UITextField

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>

Attributes inspector | Text Field

Placeholder : 흰색 미리보기 κΈ€μž

Text input traits λ₯Ό 톡해 μž…λ ₯값에 λŒ€ν•œ 섀정을 λ°”κΏ€μˆ˜μžˆμŒ

UITextFieldDelegate

It will allow our class, our ViewController, to manage the editing and validation of text and in a text-field

  1. 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(?)을 κ΄€λ¦¬ν•˜λŠ” 선택적인 ν•¨μˆ˜λ“€μ˜ λͺ¨μž„

  2. 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,

func

//μ‚¬μš©μžκ°€ ν‚€λ³΄λ“œμ˜ return keyλ₯Ό λˆŒλ €μ„ λ•Œ, bool을 λ°˜ν™˜
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
		print("pressed the return button")
		return true        
}

delegate method 호좜 μˆœμ„œ