I have some problems with swift and the NSNotificationCenter-System. I added the Observer like that:
NSNotificationCenter.defaultCenter().addObserverForName("disconnected", object: nil, queue: nil) { note in
self.btConnect.title = "Verbinden"
}
and I posted a notification like this:
NSNotificationCenter.defaultCenter().postNotificationName("disconnect", object: self)
But Nothing happens. the Observer and the Notifier are in differentness classes. Can someone help me, what I'm doing wrong?
您的通知名称不正确:“已断开连接”与“断开连接”。
Your both methods need to have the same name. Currently they are disconnected
and disconnect
. You have to change the postNotificationName
parameter from:
NSNotificationCenter.defaultCenter().postNotificationName("disconnect", object: self)
To:
NSNotificationCenter.defaultCenter().postNotificationName("disconnected", object: self)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.