I want to display a Sheet and when user clicks "OK", show another sheet.

However, the moment "OK" is clicked the whole design becomes a mess, as if the first alert sheet hadn't had enough time to disappear.

This is the code I'm using for the sheets:

#define CONFIRM_ALERT(X,Y,Z,W,V) \
NSAlert* confirmAlert = [NSAlert alertWithMessageText:X \
defaultButton:@"OK" \
alternateButton:@"Cancel" \
otherButton:nil \
informativeTextWithFormat:Y]; \
[confirmAlert beginSheetModalForWindow:Z \
modalDelegate:self \
didEndSelector:W \
contextInfo:V];

#define INFO_ALERT(X,Y,Z) \
NSAlert *infoAlert = [[NSAlert alloc] init]; \
[infoAlert addButtonWithTitle:@"OK"]; \
[infoAlert setMessageText:X]; \
[infoAlert setInformativeText:Y];\
[infoAlert setAlertStyle:NSInformationalAlertStyle]; \
[infoAlert beginSheetModalForWindow:Z modalDelegate:self didEndSelector:nil contextInfo:nil];

And how I'm using it:

- (void)doSth
{
       CONFIRM_ALERT(@"New Action", 
               @"Are you sure you want to proceed?", 
               [self window], 
               @selector(confirm:code:context:),
               nil);
}

- (void)confirm:(NSAlert*)alert code:(int)choice context:(void *)filename
{
    if (choice == NSAlertDefaultReturn)
    {
         INFO_ALERT(@"Success :-)",
         @"The Action has been successfully completed.", 
         [self window]);
    }
}

Any ideas? What am I doing wrong?

有帮助吗?

解决方案

It should work to just put [[alert window] orderOut:nil] at the top of the first alert-end method. This is actually documented in the reference for -[NSAlert beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:\].

其他提示

You have to show the sheet on the next run loop by delaying it using performSelector:withObject:afterDelay or an equivalent method.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top