Ios 未调用NotificationCenter注册的选择器
我现在有下面的代码,看看这一天是否过去了,但它似乎不起作用。我的编码正确吗Ios 未调用NotificationCenter注册的选择器,ios,swift,selector,nsnotificationcenter,Ios,Swift,Selector,Nsnotificationcenter,我现在有下面的代码,看看这一天是否过去了,但它似乎不起作用。我的编码正确吗 NotificationCenter.default.addObserver(self, selector:"calendarDayDidChange:", name:NSNotification.Name.NSCalendarDayChanged, object:nil) func calendarDayDidChange(notification : NSNotification) { // code to
NotificationCenter.default.addObserver(self, selector:"calendarDayDidChange:", name:NSNotification.Name.NSCalendarDayChanged, object:nil)
func calendarDayDidChange(notification : NSNotification) {
// code to respond to notification
}
我认为你注册观察员的方式不正确。请尝试下面的方法并检查
NotificationCenter.default.addObserver(self, selector:#selector(self.calendarDayDidChange(notification:)), name:NSNotification.Name.NSCalendarDayChanged, object:nil)
放置断点并测试。什么不起作用?@意思是在第二天测试我的应用程序后,代码没有被调用?你是如何确定的?@意思是在我的代码中,稍后使用“workoutCount”将标签重置为0,但它没有这样做。很好的提示,“calendarDayDidChange:”(看起来像Obj-C和)实际上永远不会起作用。