-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