在 Xcode 8 中出现分段错误
我最近将我的项目迁移到Swift 3。Xcode 版本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
}
当我注释掉 viewWillAppear 方法中的代码时,项目运行成功。