代码之家  ›  专栏  ›  技术社区  ›  Bruno Berisso

如何从XIB加载显示表?(马科斯)

  •  4
  • Bruno Berisso  · 技术社区  · 14 年前

    我有一个XB文件,只有一个nSPANEL,我试图把这个面板作为模态表 beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:

    我想要的是:

    ...
    MyController *controller = [[MyController alloc] init];
    
    [NSApp beginSheet:controller.panel modalForWindow:[NSApp mainWindow] modalDelegate:controller didEndSelector:nil contextInfo:nil];
    ...
    

    问题: 必须由MyController继承 NSWindowController NSObject ?我试过了 NSWindow控制器 initWithWindowNibName: 但是出口到 NSPanel

    谢谢

    1 回复  |  直到 13 年前
        1
  •  8
  •   Bruno Berisso    14 年前

    我解决了。必须停用用于图纸的窗口对象(在IB中)的几乎所有属性。我向控制器添加以下方法以显示工作表:

    - (void)showInWindow:(NSWindow *)mainWindow {
        if (!panelSheet)
            [NSBundle loadNibNamed:@"XibName" owner:self];
    
        [NSApp beginSheet:panelSheet modalForWindow:mainWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
        [NSApp runModalForWindow:panelSheet];   //This call blocks the execution until [NSApp stopModal] is called
        [NSApp endSheet:panelSheet];
        [panelSheet orderOut:self];
    }
    

    panelSheet 是板材窗口的IBOutlet。

    谢谢乔恩·赫斯和JWWalker的帮助