我正在从窗口 nib 文件中加载带有控制器的窗口。该窗口启用了“关闭时释放”选项。窗口关闭后如何释放控制器?
谢谢
在您的windowWillClose:
代码中不要忘记您需要这样做,removeObserver:
否则您的控制器将永远不会被释放,因为 NSNotificationCenter 已保留它。
在窗口控制器中订阅窗口关闭通知。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:window];
并在windowWillClose:
方法中编写代码以释放您的窗口控制器。