【发布时间】:2018-12-14 14:56:05
【问题描述】:
我在 A 视图控制器上添加了一个观察者,而视图控制器 B 在 A 上呈现。
在关闭控制器 B 时,我已经发布了通知,但它没有调用 A 中添加的选择器方法。
同样通知首先被注册并调用 post 方法。我已经检查过了。
这里是示例代码:
NotificationCenter.default.addObserver(self, selector: #selector(closButtonPressed(notification:)) ,name: Notification.Name("CloseButtonPressed"), object: nil)
@objc func closButtonPressed(notification: Notification){
}
NotificationCenter.default.post(name: Notification.Name("CloseButtonPressed"), object: self)
任何帮助将不胜感激。
【问题讨论】:
-
在
addObserver行中的closButtonPressed(notification:)前面添加self. -
试过了。不工作
-
嗯,只是为了确定。
addObserver和closButtonPressed在控制器 A 中。而post在控制器 B 中? -
在命名 Notification ala
NSNotification.Name(rawValue: "CloseButtonPressed")时也尝试使用原始值 -
是的。我认为有一些与演示有关的东西。我正在使用第三方图像查看器来显示图像。当解雇它时,我需要采取行动。这是第三方链接:github.com/aFrogleap/SimpleImageViewer
标签: ios swift notificationcenter