Creating a Modal Dialog or Window in Cocoa Objective-C?

后端 未结 2 585
闹比i
闹比i 2021-02-01 21:48

I need to create an modal dialog, which is to loaded from a nib file and should be displayed on a button click in the main window.

I can create a custom window in a nib

相关标签:
2条回答
  • 2021-02-01 22:42

    There are several ways to do this — and in fact two different kinds of modal dialog in OS X: application-modal and window-modal. Using the wrong one will annoy people. One is a sheet, which is attached to the window that it affects (save dialogs are an example of this). The other is application-modal, which blocks the whole application (open dialogs work this way, since they don't apply to any window that exists yet). Apple's sheet documentation should help get you oriented.

    0 讨论(0)
  • 2021-02-01 22:49

    Thank you...

    (Example). Create a nib with name "About"

    if(pAbtCtrl == nil)
            pAbtCtrl = [[AboutWindowController alloc] initWithWindowNibName:@"About"];
    
    pAbtWindow = [pAbtCtrl window];
    
    [NSApp runModalForWindow: pAbtWindow];
    
    [NSApp endSheet: pAbtWindow];
    
    [pAbtWindow orderOut: self];
    
    0 讨论(0)
提交回复
热议问题