NotificationCenter registered selector is not called

♀尐吖头ヾ 提交于 2019-11-28 12:38:39

问题


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
}

回答1:


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)


来源:https://stackoverflow.com/questions/45380920/notificationcenter-registered-selector-is-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!