1

我想显示一个工作表,当用户单击“确定”时,显示另一个工作表。

然而,点击“确定”的那一刻,整个设计就变得一团糟,就好像第一个警报表还没有足够的时间消失一样。

这是我用于工作表的代码:

#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];

以及我如何使用它:

- (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]);
    }
}

有任何想法吗?我究竟做错了什么?

4

2 回答 2

9

它应该可以放在[[alert window] orderOut:nil]第一个 alert-end 方法的顶部。这实际上记录在-[NSAlert beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:\].

于 2012-04-05T22:02:52.393 回答
2

performSelector:withObject:afterDelay您必须通过使用或等效方法延迟它来在下一个运行循环中显示工作表。

于 2012-04-05T18:43:49.727 回答