本文介绍了NotificationCenter注册的选择器未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前在下面有以下代码,以查看这一天是否已过,但似乎无法正常运行.我编码正确了吗?
I currently have this code below to see if the day has elapsed, but it doesn't seem to be working. Have I coded this correctly?
NotificationCenter.default.addObserver(self, selector:"calendarDayDidChange:", name:NSNotification.Name.NSCalendarDayChanged, object:nil)
func calendarDayDidChange(notification : NSNotification) {
// code to respond to notification
}
推荐答案
我认为您注册观察员的方式不正确.请尝试以下检查.
I think the way you registered observer is not correct. Please try the below and check.
NotificationCenter.default.addObserver(self, selector:#selector(self.calendarDayDidChange(notification:)), name:NSNotification.Name.NSCalendarDayChanged, object:nil)
这篇关于NotificationCenter注册的选择器未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!