如何在完成阻止后阻止NSSavePanel关闭?

时间:2013-03-02 01:11:09

标签: objective-c macos cocoa nssavepanel

如果保存文件出错,我想在保存表单上显示错误警告,如覆盖提示一样。但是,保存面板在完成块完成后立即关闭,并带有错误警报。

[panel beginSheetModalForWindow:window
              completionHandler:^(NSInteger result) {
                  if (result == NSFileHandlingPanelOKButton) {
                      NSError *error;
                      // Do my saving here...
                      if (error)
                          [[NSAlert alertWithError:error] beginSheetModalForWindow:panel
                                                                     modalDelegate:nil
                                                                    didEndSelector:nil
                                                                       contextInfo:nil];
                  }
              }];

我可以取消在完成块中隐藏NSSavePanel吗?来自代表?从什么?

1 个答案:

答案 0 :(得分:2)

我刚刚检查了TextEdit以及它在你没有确认保存的情况下做了什么,但保存的失败如下:

  1. “保存”面板汇总。
  2. 该应用尝试无法保存。 (你的街区。)
  3. 该应用程序在文档窗口中显示其错误表,“保存”面板已经消失。
  4. Screenshot of TextEdit's error sheet

    因此,如果您想要类似Apple的行为,请在文档窗口中显示警报表。

    顺便说一句,您可能对presentError:modalForWindow:delegate:didPresentSelector:contextInfo:感兴趣。