开发者

NSNotificationCenter: is it possible for it to listen in to other classes that do not explicitly post Notifications?

开发者 https://www.devze.com 2023-03-10 02:54 出处:网络
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

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开发者_Go百科 want to add postNotifications: to the View Controller. Do I have to?


No, it is not possible. You will have to add postNotifications: I'm afraid.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消