Working with multiple Windows using the Builder interface

How to work with multiple windows in Cocoa? I created a cocoa application. When I run this application, it automatically displays the default window. I added a button in the window. When I click the button, I want to open another window called MySecondWindow, which I created in IB ..

I created a Window controller (MySecondWindowController) for MySecondWindow and linked it to nib in IB. When I click the button in the main window, I call IBAction, which creates an instance of MySecondWindowController and calls method NSApp beginSheet:c [mySecondWindowObj window]. I get a message Modal session requires modal windowat NSlog. When I try to type [mySecondWindowObj window]in NSlog, it prints null..

I do not know what to do. What are the necessary things to make this work? I need help.

Thank..

+3
source share
2 answers
YourWindowController* sheet;

[[NSApplication sharedApplication] beginSheet:[sheet window]
                               modalForWindow:[[NSApplication sharedApplication] mainWindow]
                                modalDelegate:nil
                               didEndSelector:nil
                                  contextInfo:nil];

Make sure your window is created correctly. Make sure that the option "Visible at startup" in IB is not checked.

EDIT: I just noticed that you are loading this window from a separate nib file. Make sure you download it correctly. Use this:

YourWindowController* sheet = [[YourWindowController alloc] initWithWindowNibName:@"NameOfNibMinusExtension"];

and

Check and make sure that the “File Owner” type is set to your custom windowname class class and its “window” is set to a window in Nib.

Right-click (or Cmd + Click) on the File Owner and make sure that the "window" property is connected to the corresponding window. Also, make sure that the "Visible on Launch" window is NOT checked.

+3
source

Control, , MySecondWindow. , : makeKeyAndOrderFront:.

, ( NSButton) makeKeyAndOrderFront: . NSControl, / Cocoa. Builder, , MySecondWindow, - makeKeyAndOrderFront:. NSButton , , .

?

+1

Source: https://habr.com/ru/post/1790376/


All Articles