-2
之后立即删除它我最近查看了一些swift代码,我发现这个:添加观察者,然后立即删除它。那背后的逻辑是什么?为什么添加一个oberver在
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "displayPushMessage:", name: "displayMessage", object: nil)
}
//adding the observer and removing it right after whhy?? where is the logic
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
NSNotificationCenter.defaultCenter().removeObserver(self, name: "displayMessage", object: nil)
}
func displayPushMessage (notification:NSNotification) {
为什么你认为观察者在被添加后被删除? – rmaddy