Does NSViewController get notified when its view is added or removed?
For iOS, I was using UIViewController's viewWillAppear and viewWillDisappear to hook up and unhook listeners on the controller's model.开发者_JAVA技巧 This way the controller doesn't do any work if it's view is not being shown, and can make sure everything is synced up when the view is shown.
I'd like to do the same for Mac, but don't see any way that an NSViewController gets notified about its view being added or removed from the display. Should I just subclass NSViewController, add the notification methods, and have whoever adds/removes the views call those methods?
As of Yosemite, the answer is now "Yes."
This is an old question but the answer is "No, it will not be notified". You need to subclass and do it yourself. I also hooked up my subclass to the responder chain.
精彩评论