2013-11-24 4 views
0

환경 설정 윈도우를 구현하기 위해 NSWindowController를 사용하고 있습니다. Apple의 설명서에 따르면 컨트롤러와 창은 기본적으로 할당 해제되지 않았기 때문에 모든 것을 다시로드하지 않아도되므로 유용합니다. 그러나 그들의 문서는 당신이 그 행동을 무시할 수는 있지만 어떻게 설명 할 수는 없다고 말합니다.Cocoa NSWindowController 및 NSWindow Deallocing하지 않음

애플의 문서 :

When a window is closed and it is part of a document-based 
application, the document removes the window’s window 
controller from its list of window controllers. This results 
in the system deallocating the window controller and the 
window, and possibly the NSDocument object itself. When a 
window controller is not part of a document-based application, 
closing the window does not by default result in the 
deallocation of the window or window controller. This is the 
desired behavior for a window controller that manages something 
like an inspector; you shouldn’t have to load the nib file 
again and re-create the objects the next time the user requests 
the inspector. 

If you want the closing of a window to make both 
window and window controller go away when it isn’t 
part of a document, your subclass of NSWindowController 
can observe the NSWindowWillCloseNotification notification 
or, as the window delegate, implement the windowWillClose: method. 

나는 windowWillClose에서 "구현"에 대해 설명이 어디서든 찾을 수 없습니다 : 방법을.

창 컨트롤러

여기에서 볼 수있다 : 컨트롤러를 사용 https://github.com/gngrwzrd/gwpreferences/blob/master/GWPreferences/GWPreferences/GWPreferences/GWPrefsWindowController.m

여기에서 볼 수있다 : https://github.com/gngrwzrd/gwpreferences/blob/master/GWPreferences/GWPreferences/GWAppDelegate.m - 나는 시도하고 힘 릴리스 오브젝트 일부 다리 캐스팅을 시도하고있다 곳이 코드에서 볼 수 있지만, 작동하지 않습니다.

따라서 GWPrefsWindowController.dealloc 메서드는 호출되지 않습니다. 어떤 아이디어?

답변

4

나는이 질문이 오래되었다는 것을 이해하지만, 구글로부터 온 사람들에게는 대답이 아주 간단하다. 비 문서 기반 응용 프로그램, 문서에 명시된 바와 같이

, 당신은 간단하게 할 수 있습니다 당신이 그것을 호출하는 곳

  • NSWindowController에 대한 참조를 유지합니다. (이 myWindowController에 의해 참조있어 아래의 예에서,

더 많은 질문에 대답하기

  • windowWillClose: 방법에 전무로 설정하여 윈도우 컨트롤러를 출시,
  • 클래스가 NSWindowController이 프로토콜 NSWindowDelegate을 구현 호출 확인 . 컨트롤러를 인스턴스화 할 때 게으른 정확하게 대리자로 클래스를 설정 :

    -(IBAction)showMyWindowAction:(id)sender 
    { 
        // If my window controller is not nil 
        if (!myWindowController) 
        { 
         //instantiate it 
         myWindowController = [[MyWindowController alloc] initWithWindowNibName:@"myWindow"]; 
         // set your class as delegate 
         [myWindowController setDelegate:self]; 
        } 
    
        [myWindowController.window orderFront:self]; 
    } 
    

    그리고 다음을 구현 이 컨트롤러의 경우 우리가 확인되기 때문에 그것은 당신의 윈도우 컨트롤러가 지금의 dealloc 것입니다 및 NSWindowDelegate 프로토콜

    -(void)windowWillClose:(NSNotification *)notification 
    { 
        //Check if it's the right window that will close 
        if ([notification.object isEqualTo:myWindowController.window]) 
        { 
         //Set your controller to nil 
         myWindowController = nil; 
         } 
    } 
    

    0 방법은 윈도우를 표시하기 전에 무기 호입니다, 모든 작동합니다!

    이것이 기본적으로 구현되지 않은 이유는 initWithWindowNibName:이 약간 무거 우므로 dealloc을하면 창에있는 것이 무엇이든지간에 창 펜촉을로드하는 것보다 더 또는 덜 영향을 줄 수 있습니다. 파일.

    도움이 되었기를 바랍니다.

  • +0

    감사합니다. 예, 알림을 받았을 때 수행 할 작업에 대한 설명서에서 설명하지 않은 내용입니다. – gngrwzrd

    +1

    필자는 ARC가 없을 때 문서가 작성되었다고 생각하므로 암시 적으로 'windowWillClose :'에 속성을 릴리스해야한다고 암시 적으로 설명했습니다. –