NSNotificationCenter:它是否可以监听其他未明确发布通知的类?
我正在尝试监听被触发的 UIViewController
方法(-viewDidLoad
、-viewDidAppear
、-viewDidUnload
、-viewDidDisappear
等),无需修改方法中的实际代码。这不可能吗?我试图让另一个类中的观察者监听正在调用的这些方法,但我不想将 postNotifications:
添加到视图控制器。我必须这样做吗?
I am trying to listen for UIViewController
methods being triggered (-viewDidLoad
, -viewDidAppear
, -viewDidUnload
, -viewDidDisappear
and so on) without modifying the actual code in the methods. Is this impossible? I'm trying to have an observer in another class listen in for those methods being called, but I don't want to add postNotifications:
to the View Controller. Do I have to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,这是不可能的。恐怕您必须添加
postNotifications:
。No, it is not possible. You will have to add
postNotifications:
I'm afraid.我将 UINavigationController 子类化以发布您想要的通知。或者,我可以使用类别的 swizzling 来添加通知,而无需触及类的代码
I'd subclass the UINavigationController to post the notifications you want. Alternatively I'd use swizzling with a category to add the notifications without touching the code of the class