NSWindowController's window released immediately

后端 未结 1 1932
说谎
说谎 2021-01-14 06:44

I\'m trying to open a window using a NSWindowController in my app delegate. I created a basic NSWindowController with an associated NIB and try to show the window that way:<

相关标签:
1条回答
  • 2021-01-14 07:18

    You need to add a property to your app delegate (or some other object that's going to stick around for the lifetime of your app) that retains theWindowConroller. For example:

    @interface MyAppDelegate : NSObject
    
    @property (strong, nonatomic) MyWindowController * windowController;
    
    @end
    

    Then set this property when you initialize the window controller.

    @implementation MyAppDelegate
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        // Show the main window from a separate nib
        self.windowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindowController"];
        [theWindowController showWindow:self];
    }
    
    @end
    
    0 讨论(0)
提交回复
热议问题