Reputation: 23
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?
Upvotes: 1
Views: 722
Reputation: 22343
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)
Upvotes: 0
Reputation: 2875
You notification name is incorrect: "disconnected" vs "disconnect".
Upvotes: 3