从 Apple 的示例中复制/粘贴的这段代码有什么问题?警报很快出现在窗口上,然后应用程序终止(没有任何错误)。
(NSApplicationTerminateReply)applicationShouldTerminate:(NSNotification *)notification {
return NSTerminateCancel;
if (registerModified){
NSAlert *testAlert = [NSAlert alertWithMessageText:@"Voulez-vous enregister les modifications du registre?"
defaultButton:@"Enregistrer"
alternateButton:@"Ne pas enregistrer"
otherButton:nil
informativeTextWithFormat:@"Ces modifications seront permanentes."];
[testAlert beginSheetModalForWindow:[self mainWindow]
modalDelegate:self
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
#pragma unused (contextInfo)
[[alert window] orderOut:self];
}
beginSheetModalForWindow…如果你很快!