只是我,还是NotificationCenter
在 Swift 3 中变得一团糟?:)
我有以下设置:
// Yonder.swift
extension Notification.Name {
static let preferenceNotification = Notification.Name("preferencesChanged")
}
// I fire the notification elsewhere, like this:
NotificationCenter.default.post(name: .preferenceNotification, object: nil)
在我的第一个视图控制器中,这很好用:
// View Controller A <-- Success!
NotificationCenter.default.addObserver(self, selector: #selector(refreshData), name: .preferenceNotification, object: nil)
func refreshData() {
// ...
}
但是这个视图控制器:
//View Controller B <-- Crash :(
NotificationCenter.default.addObserver(self, selector: #selector(loadEntries(search:)), name: .preferenceNotification, object: nil)
func loadEntries(search:String?) {
// ...
}
...崩溃:
[NSConcreteNotification 长度]:发送到实例的无法识别的选择器
据我所知,我的观察者设置正确。知道我做错了什么吗?