Cocoa:NSApp beginSheet设置应用程序委托?

nrj*_*nrj 2 cocoa delegates nsapplication cocoa-sheet

我试图在我的应用程序中显示自定义工作表,但我认为我做错了什么.虽然一切似乎都很好,但我有一个相当奇怪的副作用.(花了几个小时才算出来).事实证明,每当我在我的应用程序中显示一个工作表时,Application委托就会被设置为工作表的实例,因此我的Controller将被取消设置为委托导致各种问题.

我创建了一个名为FailureSheet.xib的NIB文件.我在IB中布置了我的接口,然后创建了一个名为'FailureSheet.m'的'NSWindowController'的子类,我将其设置为File的Owner.这是我的FailureSheet类:

#import "FailureSheet.h"

@implementation FailureSheet  // extends NSWindowController

- (id)init
{
    if (self = [super initWithWindowNibName:@"FailureSheet" owner:self])
    {

    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (IBAction)closeSheetTryAgain:(id)sender
{   
    [NSApp endSheet:[self window] returnCode:1];
    [[self window] orderOut:nil];
}

- (IBAction)closeSheetCancel:(id)sender
{
    [NSApp endSheet:[self window] returnCode:0];
    [[self window] orderOut:nil];
}

- (IBAction)closeSheetCancelAll:(id)sender
{
    [NSApp endSheet:[self window] returnCode:-1];
    [[self window] orderOut:nil];
}

@end
Run Code Online (Sandbox Code Playgroud)

这里没有什么复杂的事情发生.现在这就是我在'Controller'类中显示FailureSheet的方法:

sheet = [[FailureSheet alloc] init];

[NSApp beginSheet:[sheet window]
   modalForWindow:window
    modalDelegate:self
   didEndSelector:@selector(failureSheetDidEnd:etc:etc:)
      contextInfo:nil];
Run Code Online (Sandbox Code Playgroud)

现在,如果我在显示工作表之前记录了[NSApp委托]的内容,那么<Controller-0x012345>是正确的.然后,在运行此代码并且我的工作表启动后,如果我再次记录它,则它是<FailureSheet-0xABCDEF>.

不知道我在这里做错了什么 - 有什么想法吗?

nrj*_*nrj 5

这是那些"我是白痴"的答案之一.

事实证明,我偶然在我的工作表的NIB文件中在应用程序和文件所有者(FailureSheet)之间建立了一个连接,将其设置为委托.因此,每次加载它都会覆盖我在MainMenu NIB文件中的现有委托连接.