我最近查看了一些快速代码,发现了这一点:添加观察者,然后立即将其删除。这背后的逻辑是什么?
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) {