【发布时间】:2015-08-18 15:50:07
【问题描述】:
我有 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)
}
但这无济于事,
在视图控制器中
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
我该如何解决这个问题?
【问题讨论】:
标签: ios swift nsnotificationcenter