我最近将我的项目迁移到了Swift 3.Xcode Version 8.0(8A218a)每当我使用UIKeyboardWillShow通知时,我都会收到此错误:
由于信号命令失败:分段错误:11`
这就是我在我的代码中使用通知的方式:
override func viewWillAppear(_ animated: Bool) {
NotificationCenter.default.removeObserver(NSNotification.Name.UIKeyboardWillShow)
NotificationCenter.default.removeObserver(NSNotification.Name.UIKeyboardWillHide)
NotificationCenter.default.addObserver(self, selector: #selector(myViewController.keyboardWillShow(_:)), name:NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(myViewController.keyboardWillHide(_:)), name:NSNotification.Name.UIKeyboardWillHide, object: nil)
}
func keyboardWillShow(_ sender: Notification) {
//keyboardWillShow Method
}
func keyboardWillHide(_ sender: Notification) {
// keyboardWillHide Method
}
Run Code Online (Sandbox Code Playgroud)
当我在viewWillAppear方法中注释掉代码时,项目成功运行.