2015-02-11 57 views
1

我在swift和NSNotificationCenter-System上遇到了一些问题。 我说这样的观察:Swift NSNotificationCenter不会启动

NSNotificationCenter.defaultCenter().addObserverForName("disconnected", object: nil, queue: nil) { note in 
     self.btConnect.title = "Verbinden" 
} 

和我张贴这样的通知:

NSNotificationCenter.defaultCenter().postNotificationName("disconnect", object: self) 

但没有任何反应。观察者和通知者处于不同类别中。 有人可以帮助我,我做错了什么?

回答

3

您的通知名称不正确:“断开连接”与“断开连接”。

0

您的两个方法需要具有相同的名称。目前他们是disconnecteddisconnect。你必须在postNotificationName参数从改变:

NSNotificationCenter.defaultCenter().postNotificationName("disconnect", object: self) 

要:

NSNotificationCenter.defaultCenter().postNotificationName("disconnected", object: self)