【发布时间】:2017-03-09 05:20:54
【问题描述】:
我在viewdidload()使用这个代码
NotificationCenter.default.addObserver(self, selector: Selector(("appWillEnterForeground:")), name: NSNotification.Name.UIApplicationDidBecomeActive, object: UIApplication.shared)
调用这个函数
func appWillEnterForeground(notification: NSNotification!) {
// update label text here
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(true)
NotificationCenter.default.removeObserver(self)
}
但该应用程序在返回前台时崩溃
unrecognized selector sent to instance 0x160db800
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ appWillEnterForeground:]: unrecognized selector sent to instance 0x160db800'
【问题讨论】: