beginSheetModalForWindow

时间:2012-05-19 11:38:28

标签: objective-c cocoa alert

这段代码有什么问题,从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 ...如果你的速度非常快!

0 个答案:

没有答案