Question

I'm trying to open a window like a sheet so that it appears down below the toolbar. I've used the O'Reilly tutorial to do this. However, I can get past this error: Modal session requires modal window.

The window loads as a window if I have "Visible At Launch" checked.

Whether it is checked or not I get the "Modal session requires modal window" error.

I have a Window.xib, ProgressModal.xib.

In the Window implementation file I use:

-(IBAction)loadProgress:(id)sender{
    [self progressStatus:progressWindow];
}

- (void)progressStatus:(NSWindow *)window {

    [NSApp beginSheet: window
       modalForWindow: mainWindow
        modalDelegate: nil
       didEndSelector: nil
          contextInfo: nil];
    [NSApp runModalForWindow: window];
    [NSApp endSheet: window];
    [window orderOut: self];

}

- (IBAction)cancelProgressScrollView:(id)sender {
    [NSApp stopModal];
}

I may have the ProgressModal.xib setup wrong. I have an NSObject in it that has "Window" as its class. All the connections are made through that.

But again, it loads the window just won't load it as a modal.

Any ideas?

Was it helpful?

Solution 2

As I stated above, I dragged an object over in the progressModal window and made my connections through that. What I should have done was made the File's owner my Window class. Changing that fixed the problem.

I got this from http://www.youtube.com/watch?v=QBkO6TD-fWA

OTHER TIPS

Put the following in the first line of your progressStatus method:

NSLog(@"%@", window);

If you see the log output is null, that's the reason why.

Steps to create a modal sheet using XIB:

  1. Drag a panel to your MainMenu.xib
  2. Add @property (assign) IBOutlet NSPanel *sheetPanel; in your AppDelegate.h file
  3. @synthesize sheetPanel = _sheetPanel; in the AppDelegate.m file
  4. Link a New Referencing Outlet of the panel in the MainMenu.xib created in the step 1 to the sheetPanel property created in step 2.
  5. Using following code to show the modal sheet:

    [NSApp beginSheet:_sheetPanel
       modalForWindow:_mainWindow
        modalDelegate:self
       didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
          contextInfo:nil];
    

Edit: I assumed you wanted a modal window. If you want a sheet, don't use runModalForWindow: at all.

Try this:

[NSApp beginSheet: window
   modalForWindow: mainWindow
    modalDelegate: nil
   didEndSelector: nil
      contextInfo: nil];

It's a good idea to define a callback just in case you need it though; e.g.

[NSApp beginSheet: window
   modalForWindow: mainWindow
    modalDelegate: self
   didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
      contextInfo: nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top