Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用NotificationCenter注册的选择器_Ios_Swift_Selector_Nsnotificationcenter - Fatal编程技术网

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和)实际上永远不会起作用。