【发布时间】:2016-11-16 23:18:36
【问题描述】:
首先请注意,我没有像其他各种问题中所述那样多次注册为观察员。
当我在本机日历应用程序中更改某些内容并返回到我的应用程序时,选择器会被调用 4-5 次并发出不同的通知。
在 viewDidLoad 中,我删除了所有可能的观察者并注册了一次 agian:
NotificationCenter.default.removeObserver(self)
NotificationCenter.default.addObserver(self, selector: #selector(reloadModelData(notification:)), name: Notification.Name.EKEventStoreChanged, object: nil)
对应的方法:
@objc private func reloadModelData(notification: NSNotification) {
debugPrint("method called \(notification)")
}
导致这个输出
"方法称为 NSConcreteNotification 0x170246300 {name = EKEventStoreChangedNotification; object = ; userInfo = {\n EKEventStoreChangedObjectIDsUserInfoKey = (\n \"x-apple-eventkit:///Location/p259707\",\n \"x-apple -eventkit:///Event/p264955\"\n);\n}}" "方法称为 NSConcreteNotification 0x174258840 {name = EKEventStoreChangedNotification; object = ; userInfo = {\n EKEventStoreChangedObjectIDsUserInfoKey = (\n \"x-apple-eventkit:///Location/p259707\",\n \"x-apple-eventkit: ///事件/p264955\"\n);\n}}" "方法称为 NSConcreteNotification 0x17024b250 {name = EKEventStoreChangedNotification; object = ; userInfo = {\n EKEventStoreChangedObjectIDsUserInfoKey = (\n \"x-apple-eventkit:///Location/p259707\",\n \"x-apple-eventkit: ///事件/p264955\"\n);\n}}" "方法称为 NSConcreteNotification 0x174253b00 {name = EKEventStoreChangedNotification; object = ; userInfo = {\n EKEventStoreChangedObjectIDsUserInfoKey = (\n \"x-apple-eventkit:///Location/p259707\",\n \"x-apple-eventkit: ///事件/p264955\"\n );\n}}"
有谁知道如何解决这个问题。意思是在重新进入应用时只收到该观察者的一次调用?
【问题讨论】:
-
请说明您遇到的问题。当你征求建议时,不清楚你的意思是什么。
-
我相应地编辑了问题
-
您找到解决方案了吗?我有同样的问题
标签: ios swift nsnotificationcenter