- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我最近将我的项目迁移到了 Swift 3。 Xcode 版本 8.0 (8A218a)每当我使用 UIKeyboardWillShow 通知时,我都会收到此错误:
Command failed due to signal: Segmentation fault: 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 方法中的代码时,项目成功运行。
最佳答案
主题:Segmentation fault: 11,这是Xcode8/Swift3的bug,你应该发一个bug report .
关于您的代码:
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 崩溃。
关于ios - 段错误 : 11; (xcode 8, Swift 3) 使用 NotificationCenter 后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39426535/
我已经搜索过了,但问题仍然存在。我找到了 this great question但不幸的是它对我不起作用。这是我第一次使用 NotificationCenter,当我想将数据传递给 XLPagerTa
我目前在下面有这段代码来查看这一天是否已经过去,但它似乎没有用。我是否正确编码? NotificationCenter.default.addObserver(self, selector:"cale
我想检测网络变化。例如,从 wifi 切换到 4G 或返回时。但是我的代码没有检测到这些变化。当应用程序启动时,我只得到一些输出。 我有这个代码: import ReachabilitySwift o
我在 AppDelegate 中调用函数 performActionForShortcutItem 时在应用程序中实现了 3D Touch Quick Action,我通过其中的 Notificati
我已经尝试了好几个小时让观察员收到通知帖子,但每次尝试都失败了。我将观察者放入我的 Root View Controller 中,它是一个嵌入式选项卡 Controller ,并试图让其中一个选项卡
前言 本文主要介绍了关于Swift通知中心(NotificationCenter)使用的相关内容,NotificationCenter是Swift中一个调度消息通知的类,采用单例模式设计,实现传值
收到 IAP 购买通知,然后我从我的服务器请求交易。 如果交易正常,下载歌曲并播放。 我用的是 RxSwift,下面的代码可以用,我想改进一下。 NotificationCenter.default.
我在我的 viewController 中添加了一些观察者 -- applicationWillResignActive、applicationDidEnterBackground 以及许多其他观察者
我想接收来自其他应用程序的通知,这些通知会出现在锁定屏幕上 - 类似于 Pebble 和其他智能 watch 接收它们的方式。 很容易通过注册通知 NSNotificationCenter.defau
我目前正在开发一款在一个 ScrollView 中包含多个文本字段和 2 个 TextView 的应用。在键盘外观上,我已经能够更改 ScrollView 的内容插入,以便不隐藏字段。我遇到的问题是我
我有 3 个通知: NotificationCenter.default.post(name:NSNotification.Name("Notification1"), object: nil) No
我有代码: 主视图.swift: override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(true)
我有一些使用 block /尾随闭包语法创建的通知,如下所示: NotificationCenter.default.addObserver(forName: .NSManagedObjectCont
我不确定我是否在这里做错了什么: 我正在 awakeFromNib 中使用此代码段注册工作区通知 [[[NSWorkspace sharedWorkspace] notificationCenter]
我的项目中有这段代码: func viewDidLoad() { super.viewDidLoad() NotificationCenter.default.addObserver(
我正在尝试创建让我的 View 在键盘打开后移动。但我遇到了一个非常意想不到的问题。 这是我的代码: override func viewDidLoad() { super.viewDidLo
我在尝试导入NotificationCenter框架的两个 Controller 中遇到模块错误。我已在“链接的框架和库”中添加了框架,但仍然收到错误。 我什至尝试了cmd + shift + k,但
我已将源代码从 Swift 2.2 更新到 Swift 3.0 以用于推送通知。但我无法获取用户信息。它将返回零。谁能帮忙? 在应用程序委托(delegate)中接收推送通知: func applic
在从 swift3 到 swift4 的转换过程中,转换器已将 NotificationCenter 更改为以下 View : NotificationCenter.default.addObser
这个问题在这里已经有了答案: URLSession.shared.dataTaskPublisher not working on IOS 13.3 (3 个答案) 关闭 3 年前。
我是一名优秀的程序员,十分优秀!