moldov
moldov

Reputation: 31

Can't open a sheet on a window twice

I'm opening a sheet on a window , the first time the sheet opens correctly, but if I close it, and try to open again it doesn't work, I just get the system alert sound.

- (IBAction) showSpeedSheet:(id)sender
{

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

}

-(IBAction)endSpeedSheet:(id)sender
{

 [NSApp endSheet:addEditPackagePanel];
 [addEditPackagePanel orderOut:sender];


}

I can't find what's wrong, the app doesn't print any error on the log.

Upvotes: 0

Views: 919

Answers (2)

Kevin Grant
Kevin Grant

Reputation: 5431

A delegate is not required.

The beep occurs because the system believes there is already a sheet open on the window (whether or not that sheet is technically visible). It's not the greatest error reporting, but that's what it is.

In my code sheets have window controllers and I do both of the following steps in every action that is attached to a sheet-closing button:

[NSApp endSheet:[windowController window]];
[windowController close];

With these steps, subsequent sheets are able to display without beeping.

Upvotes: 4

user544565
user544565

Reputation:

I think you may need to implement the modal delegate and didEndSelector. The orderOut should be called from the did-end selector.

[NSApp beginSheet:addEditPackagePanel
 modalForWindow:[[NSApp delegate] window]
 modalDelegate: self
 didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
 contextInfo: nil];

and

- (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void*)contextInfo
{
    [sheet orderOut:self];
}

I believe control is sent to the did-end selector has soon as endSheet is called.

Upvotes: 0

Related Questions