Việ*_* Lê 3 nsnotificationcenter ios swift swift3 swift4.2
我正在尝试将此代码从 Swift 3 更新到 Swift 4.2
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: .UIKeyboardDidShow, object: nil);
Run Code Online (Sandbox Code Playgroud)
到目前为止,我刚刚尝试了编译器给出的自动更正。这导致如下代码:
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: .UIResponder.keyboardDidShowNotification, object: nil);
Run Code Online (Sandbox Code Playgroud)
只需替换.UIResponder.keyboardDidShowNotification为UIResponder.keyboardDidShowNotification,它将解决您的问题。
最终代码将是:
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2914 次 |
| 最近记录: |