如果保存文件出错,我想在保存表单上显示错误警告,如覆盖提示一样。但是,保存面板在完成块完成后立即关闭,并带有错误警报。
[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吗?来自代表?从什么?
答案 0 :(得分:2)
我刚刚检查了TextEdit以及它在你没有确认保存的情况下做了什么,但保存的失败如下:
因此,如果您想要类似Apple的行为,请在文档窗口中显示警报表。
顺便说一句,您可能对presentError:modalForWindow:delegate:didPresentSelector:contextInfo:
感兴趣。