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方法中的代码时,项目将成功运行。
发布于 2016-09-10 14:01:15
主题:分段错误: 11,它是Xcode8 8/Swift3 3的一个bug,您应该发送一个错误报告。
关于你的代码:
NotificationCenter.default.removeObserver(NSNotification.Name.UIKeyboardWillShow)
NotificationCenter.default.removeObserver(NSNotification.Name.UIKeyboardWillHide)没有方法移除仅指定其名称的观察者。您需要为removeObserver(_:)指定观察者对象。
我不确定这是您想要的,但是您可以使用这样的removeObserver(_:name:object:)方法:
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil)我相信这不会毁了你的Xcode。
发布于 2016-10-13 08:55:33
在相同的条件和环境(Swift 3,Xcode 8)中,我也有相同的问题,为了解决这个问题,您应该放置:
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil)而不是:
NotificationCenter.default.removeObserver(NSNotification.Name.UIKeyboardWillShow)
NotificationCenter.default.removeObserver(NSNotification.Name.UIKeyboardWillHide)https://stackoverflow.com/questions/39426535
复制相似问题