显示2张/面板 - 一个接一个

时间:2013-08-19 10:02:37

标签: objective-c cocoa nsalert

我试图一个接一个地显示2张(面板)。然而,看起来第一张纸没有足够的时间在第二张纸出现之前关闭 - 所以,它最终会变得非常混乱。

这是我的代码......

#define DRK_ALERT_YESNO_SHOW(X,Y,W) \
NSAlert* yesnoAlert = [NSAlert alertWithMessageText:X \
defaultButton:@"Yes" \
alternateButton:@"No" \
otherButton:nil \
informativeTextWithFormat:Y]; \
[yesnoAlert beginSheetModalForWindow:[[NSApp delegate] window] \
modalDelegate:self \
didEndSelector:W \
contextInfo:nil];

// Open File Sheet

#define DRK_OPENFILE_SHEET_BEGIN(X,Y,Z,A) NSOpenPanel *openPanel = [NSOpenPanel openPanel];\
[openPanel setAllowsMultipleSelection: NO];\
[openPanel setCanChooseDirectories:NO];\
[openPanel setCanCreateDirectories:NO];\
[openPanel setCanChooseFiles:YES];\
[openPanel setShowsHiddenFiles:YES];\
[openPanel setPrompt:Y];\
[openPanel setAllowedFileTypes:A];\
[openPanel beginSheetModalForWindow:X completionHandler:^(NSInteger result) {\
    if (result == NSFileHandlingPanelOKButton) {\
        NSString* Z = [openPanel filename];

#define DRK_OPENFILE_SHEET_END }\
}];

实际代码

- (IBAction)openDo:(id)sender {

    DRK_ALERT_YESNO_SHOW(@"Are you sure you want to discard changes?",
                         @"You may lose any changes you have made to your current projects.",
                         @selector(shouldOpenDo:code:context:));

}

- (void)shouldOpenDo:(NSAlert*)alert code:(int)choice context:(void *)context
{
    if (choice==NSAlertDefaultReturn)
    {
        DRK_OPENFILE_SHEET_BEGIN(([[NSApp delegate] window]), @"Open Project", filename,(@[@"txt"]));

        // Yep, we can now open the file: filename

        DRK_OPENFILE_SHEET_END
    }
    else
    {
        // nope, don't open anything
    }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

好的,这就是全部:

[[alert window] orderOut:nil];

DRK_OPENFILE_SHEET_BEGIN之前。