【问题标题】:Displaying NSAlert sheet modals one after the other一个接一个地显示 NSAlert 表单模式
【发布时间】:2012-04-19 06:44:52
【问题描述】:

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

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

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

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

有什么想法吗?我做错了什么?

【问题讨论】:

    标签: objective-c cocoa modal-dialog nsalert


    【解决方案1】:

    [[alert window] orderOut:nil] 放在第一个警报结束方法的顶部应该可以。这实际上记录在-[NSAlert beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:\] 的参考资料中。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-04
        • 2018-07-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多