开发者

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 fi开发者_JS百科nd what's wrong, the app doesn't print any error on the log.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜