小编Dee*_*put的帖子

分段故障:11; (xcode 8,Swift 3)使用NotificationCenter后

在Xcode 8中获取分段错误

我最近将我的项目迁移到了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方法中注释掉代码时,项目成功运行.

ios notificationcenter swift3 xcode8

3
推荐指数
1
解决办法
1158
查看次数

标签 统计

ios ×1

notificationcenter ×1

swift3 ×1

xcode8 ×1