【发布时间】:2009-03-03 01:22:56
【问题描述】:
当我显示这样的 NSAlert 时,我会立即得到响应:
int response;
NSAlert *alert = [NSAlert alertWithMessageText:... ...];
response = [alert runModal];
问题在于这是应用程序模式,而我的应用程序是基于文档的。我使用工作表在当前文档的窗口中显示警报,如下所示:
int response;
NSAlert *alert = [NSAlert alertWithMessageText:... ...];
[alert beginSheetModalForWindow:aWindow
modalDelegate:self
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:&response];
//elsewhere
- (void) alertDidEnd:(NSAlert *) alert returnCode:(int) returnCode contextInfo:(int *) contextInfo
{
*contextInfo = returnCode;
}
唯一的问题是beginSheetModalForWindow: 会立即返回,因此我无法可靠地向用户提问并等待回复。如果我可以将任务分成两个区域,但这没什么大不了的。
我有一个循环处理大约 40 个不同的对象(在树中)。如果一个对象失败,我希望显示警报并询问用户是继续还是中止(在当前分支继续处理),但由于我的应用程序是基于文档的,Apple Human Interface Guidelines 要求在警报出现时使用工作表特定于文档。
如何显示警报表并等待响应?
【问题讨论】:
标签: cocoa macos alerts document-based