Objective c 应用程序:openFile:donds';我在发射时没有接到电话

Objective c 应用程序:openFile:donds';我在发射时没有接到电话,objective-c,xcode,macos,cocoa,Objective C,Xcode,Macos,Cocoa,我正在使用我的第一个Mac应用程序,它非常棒。除了一个问题。 我的应用程序使用PNG图像创建新图像,用户可以将其PNG图像拖动到一个框中,并显示NSOpenPanel以选择保存位置 但是,当我退出应用程序并右键单击PNG图像并选择我的应用程序时,NSOpenPanel不会显示。 如果应用程序处于活动状态,我也会这样做。。没问题。。它显示NSOpenPanel,并对图像执行任何需要执行的操作。只是在发射时没有 我的问题:为什么不呢 我的代码: AppDelegate: - (BOOL)applic

我正在使用我的第一个Mac应用程序,它非常棒。除了一个问题。 我的应用程序使用PNG图像创建新图像,用户可以将其PNG图像拖动到一个框中,并显示NSOpenPanel以选择保存位置

但是,当我退出应用程序并右键单击PNG图像并选择我的应用程序时,NSOpenPanel不会显示。 如果应用程序处于活动状态,我也会这样做。。没问题。。它显示NSOpenPanel,并对图像执行任何需要执行的操作。只是在发射时没有

我的问题:为什么不呢

我的代码:
AppDelegate:

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
    NSURL *fileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://localhost/%@", filename]];

    [_infoLabel setTitleWithMnemonic:NSLocalizedString(@"Drag SOMETHING SOMETING here!", @"AppDelegate")]; // Debug text

    BOOL returnValue = [Resizer loadFilename:fileURL];

    if (returnValue)
    {
        [_dragDrop setImage:[[NSImage alloc] initWithContentsOfFile:filename]];
    }

    return returnValue;
}

- (void)didLoadSourceImageSuccessfull:(NSImage *)image
{
    [Resizer selectDestinationPath];
}
调整器类:

+ (BOOL)loadFilename:(NSURL *)pathToFile
{
    _sourcePath = pathToFile;

    if ([self sourceFileIsValid])
    {
        [self didLoadSourceImageSuccessfull:[[NSImage alloc] initWithContentsOfURL:_sourcePath]];
        return TRUE;
    }
    else {
        _sourcePath = nil;
        return FALSE;
    }
}

+ (void)selectDestinationPath
{
    NSOpenPanel* openDlg = [NSOpenPanel openPanel];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(destinationSavePanelDidClose:)
                                                 name:NSWindowDidEndSheetNotification
                                               object:_window];

    [openDlg setCanChooseFiles:NO];
    [openDlg setCanCreateDirectories:YES];
    [openDlg setCanChooseDirectories:YES];
    [openDlg setCanSelectHiddenExtension:NO];

    [openDlg beginSheetModalForWindow:_window completionHandler:^(NSInteger result) {
        if (result == NSFileHandlingPanelOKButton) {
            _destinationpath =  [[openDlg URLs] objectAtIndex:0];
        }
    }];
}

可能是您试图在显示或加载
\u窗口之前打开该对话框。
尝试在窗口控制器或应用程序代理的方法
-(void)awakeFromNib
中打开对话框,例如:

- (void)awakeFromNib {  
    if (isFileSentToApplication) [Resizer selectDestinationPath];  
}

如果您的控制器类是
NSWindowController
的子类,您也可以在
-(void)windowDidLoad

中执行此操作。我们可以查看
AppDelegate.h
Resizer.h
吗?另外,在
+[Resizer loadFilename::
中调用
[self-didLoadSourceImageSuccessfull:…]
,这相当于
+[Resizer-didLoadSourceImageSuccessfull:
:该方法的实现在哪里(我想我不明白为什么
AppDelegate
有一个
-didLoadSourceImageSuccessfull:
实例方法,而
Resizer
有一个
+didLoadSourceImageSuccessfull:
类方法)另外,在 Rsisiz 类中,您直接从类方法中访问 SooPixATS< <代码> > <代码> >命中路径> />代码>和<代码> >窗口> /代码>;这些定义在哪里?您可能需要考虑一个基于文档的应用程序,该应用程序为您处理大部分这些应用程序。(我不知道你在做什么,所以我不知道这是否适合你。)