我的viewController以及內側的viewDidLoad中我有斯威夫特 - 通知觀察者多次調用
NSNotificationCenter.defaultCenter().addObserver(self, selector: "showNextQuestions", name: "showNextQuestionsID", object: nil)
在另一個控制器我有
NSNotificationCenter.defaultCenter().postNotificationName("showNextQuestionsID", object: nil)
如果我從應用回家並啓動它再次發揮作用showNextQuestionID觸發兩次。
我試圖用
func applicationDidEnterBackground(application: UIApplication) {
NSNotificationCenter.defaultCenter().removeObserver(self, name: "showNextQuestionsID", object: nil)
}
但是,這並沒有幫助,
和的viewController
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
我該如何解決這個問題?
是否有另一種方式是不viewWillDisappear?我需要在ViewController中更改UI,其中observer在其他控制器上的用戶註冊時進行註冊。在用戶到達此處之前,必須更換控制器 –