La sesión modal requiere una ventana modal

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.

¿Alguna idea?

preguntado el 29 de julio de 12 a las 23:07

3 Respuestas

Put the following in the first line of your progressStatus método:

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. Añada @property (assign) IBOutlet NSPanel *sheetPanel; en tu AppDelegate.h presentar
  3. @synthesize sheetPanel = _sheetPanel; en la AppDelegate.m presentar
  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];
    

Respondido el 11 de enero de 15 a las 12:01

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.

Tengo esto de http://www.youtube.com/watch?v=QBkO6TD-fWA

Respondido 31 Jul 12, 00:07

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

Prueba esto:

[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];

Respondido 30 Jul 12, 01:07

I do want a modal. I just want it to animate in like a sheet under the toolbar. And I want to avoid the error, obviously. Are you saying that adding a @selector will fix it? - Micrófono de hierro

The same method (beginSheet:...) spawns windows with two possible behaviors: blocking one window, or the whole app. If you set modalForWindow:nil, entonces runModalForWindow: is OK (followed immediately by endSheet:, orderOut: as you have) and stopModal: does end it; but that's not animated or under the toolbar. If you do planificadas modalForWindow:mainWindow, Que no utilizan el runModalForWindow: or stopModal: and the sheet is open asynchronously; something, somewhere (typically a button) calls endSheet: y orderOut: at an appropriate time. - kevin subvención

Ignore my @selector suggestion for now; that tells you when the sheet has closed but you don't appear to need that information. - kevin subvención

I deleted [NSApp runModalForWindow: window]; I deleted [NSApp endSheet: window]; I deleted [window orderOut: self]; I ran it again and got the same error: "Modal session requires modal window." It looks like your first "Try this:" section. It still doesn't work. - Micrófono de hierro

By the way, progressWindow is declared like this in the header file: IBOutlet NSWindow *progressWindow; - Micrófono de hierro

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.