麻烦使用自定义模态表与Cocoa

Dav*_*Nix 4 macos cocoa objective-c cocoa-sheet

我的目标:当应用程序通过冗长的循环时,显示带有确定的NSProgressIndicator的自定义工作表.我希望工作表是应用程序模式,而不是文档模式.用户无法关闭模态表.他们必须等待应用程序完成循环处理.

问题:我无法将自定义工作表附加到窗口.它显示为缺少窗口标题栏的单独窗口(如表单所示).此外,当循环结束时,纸张不会释放(不会关闭).

我有两个单独的nib文件用于工作表和主应用程序窗口,还有两个控制器类用于每个窗口.

以下是相关信息:自定义工作表的控制器实现:

@implementation ProgressSheetController //subclass of NSPanel

-(void)showProgressSheet:(NSWindow *)window
{
    //progressPanel is an IBOutlet to the NSPanel
    if(!progressPanel)
        [NSBundle loadNibNamed:@"ProgressPanel" owner:self];

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

    //modalSession is an instance variable
    modalSession = [NSApp beginModalSessionForWindow:progressPanel];

    [NSApp runModalSession:modalSession];
}

-(void)removeProgressSheet
{
    [NSApp endModalSession:modalSession];
    [NSApp endSheet:progressPanel];
    [progressPanel orderOut:nil];
}

//some other methods 
@end
Run Code Online (Sandbox Code Playgroud)

主应用程序窗口的实现.testFiles方法是一个连接到按钮的IBAction.

@implementation MainWindowViewController //subclass of NSObject

-(IBAction)testFiles:(id)sender;
{
    //filesToTest is a mutable array instance variable
    int count = [filesToTest count];

    float progressIncrement = 100.0 / count;

    ProgressSheetController *modalProgressSheet = [[ProgressSheetController alloc] init];
    [modalProgressSheet showProgressSheet:[NSApp mainWindow]];

    int i,
    for(i=0; i<count; i++)
    {
        //do some stuff with the object at index i in the filesToTest array

        //this method I didn't show in ProgressSheetController.m but I think it's self explanatory
        [modalProgressSheet incrementProgressBarBy:progressIncrement];
    }
    //tear down the custom progress sheet
    [modalProgressSheet removeProgressSheet];
    [modalProgressSheet release];
}
@end
Run Code Online (Sandbox Code Playgroud)

一想法:我是否正确地进行了分类?我应该使用NSWindowController吗?预先感谢您的帮助!

Dav*_*Nix 15

发现这个宝石做一些谷歌搜索.Interface Builder中我的NSPanel的行为设置为"在启动时可见",这是使用IB时新窗口的默认值.发生的事情是,一旦笔尖被装上,窗口就会被显示出来[NSApp beginSheet:...].因此,取消选中"在启动时可见"选项可以解决我的问题,现在一张工作表就像我想要的那样连接到窗口.