Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a NSPanel modally popuped from NSWindow (Cocoa programming)

like NSPanel displayed after a button clicked in the NSWindow.

I looked for a lot but there is no simple example. Thanks for any help.

like image 745
droughtrain Avatar asked Jan 15 '23 18:01

droughtrain


1 Answers

It can be done like this:

-(IBAction)showButtonAction:(id)sender {
    [[NSApplication sharedApplication] beginSheet:panelOutlet
                                   modalForWindow:self.window
                                    modalDelegate:self
                                   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
                                      contextInfo:nil];
}

Attention:

Don't forget to uncheck NSPanel's Visible At Launch checkbox in Attributes Inspector and Release When Closed if you will use this panel not once.

Result:

Screenshot image

like image 123
Justin Boo Avatar answered Jan 30 '23 23:01

Justin Boo