티스토리 뷰
1. someTextField.resignFirstResponder()
resignFirstResponder() is good to use any time you know exactly which text field is the first responder and you want to resign its first responder status. This can be slightly more efficient then the alternative, but if you're doing something such as creating a custom control, this can make plenty of sense. Perhaps you have a text field, and when the "Next" button is pressed, you want to get rid of the keyboard and present a date picker, for example. Here, I would definitely use resignFirstResponder()
2. self.view.endEditing(true)
I typically reserve this for scenarios when I just absolutely need to clear the keyboard no matter what is currently going on, for whatever reason. Perhaps, I've got a slide-over menu? Just before this slides out, no matter what is going on, the keyboard should go away, so I'll make sure everything resigns its first responder status. It's important to note that endEditing() will look through the entire hierarchy of subviews and make sure whatever is the first responder resigns its status. This makes it less efficient then calling resignFirstResponder() if you already have a concrete reference to the first responder, but if not, it's easier than finding that view and having it resign.
1번은 특정 텍스트필드를 고정해야하고, 2번은 전체 뷰에 대해서 키보드를 닫을 수 있다. 1이 더 효율적이다.
'macOS, iOS' 카테고리의 다른 글
[iOS] xcode에 preview 기능이 있다...? (0) | 2019.09.24 |
---|---|
[Swift] default parameter (0) | 2019.09.20 |
table view separator(나눠주는 선) 꽉 차게 하기 (0) | 2019.09.20 |
테이블뷰 footer 추가해서 빈 줄 안보이게 하기 (0) | 2019.09.17 |
static func 란? (0) | 2019.09.11 |