2012-04-08 5 views

답변

12

는 내가의 ViewController에서 사용

//initWithNibName 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:self.view.window]; 

- (void)windowWillClose:(NSNotification *)notification 
    { 
     NSWindow *win = [notification object]; 
     //... 
    } 
+3

또는 당신이'NSWindowsDelegate'로'NSWindowController'을 설정 할 수있다'[self.window의 setDelegate : 자기]' 컨트롤러 클래스에'- (void) windowWillClose : (NSNotification *) notification'을 추가하십시오. –

1

NSWindowDelegate 프로토콜을 준수하도록 사용자 지정 클래스를 선언 할 수 있습니다. 윈도우를 닫기 전에 뭔가를 (하나 아마도 windowWillClose)

설정 사용자 정의 클래스의 인스턴스는

그런 다음 다음 방법 중 하나를 사용하여 윈도우의 대표가 될 수 있습니다.

- (BOOL)windowShouldClose:(id)sender 
- (void)windowWillClose:(NSNotification *)notification 
관련 문제