문제

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