开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜