2011-07-12 47 views
0

点击一个按钮,我使用下面的代码在Mac应用程序警报OK按钮不起作用

testViewController *myWindowController = [[testViewController alloc] initWithWindowNibName:@"RecordingsViewController"]; 

[myWindowController setDelegate:self]; 
activeModalWindow = [myWindowController window]; 

[NSApp beginSheet:[myWindowController window] 
    modalForWindow:[self window] 
    modalDelegate:self 
    didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) 
     contextInfo:nil]; 
[NSApp runModalForWindow:[myWindowController window]]; 

[[myWindowController window] orderOut: self]; 

从这个testViewController,我显示警报使用的代码

NSString *theAlertMessage = [NSString stringWithFormat: @"Already added"]; 
NSRunAlertPanel(@"", theAlertMessage, @"OK", nil, nil); 

但点击此提醒的确定按钮。我的警报仍在屏幕上。请帮忙!

+0

奇怪,这对我有用,你在调试器控制台中是否有错误/警告信息? –

+0

没有错误/警告 – Swastik

+0

你可以请尝试用简单的框架使用NSRunAlertPanel来构建新的项目,以验证其系统中的功能? (为了排除这个问题只在这个项目中出现的可能性) –

回答

0

找到替代方案,它完美

NSString *theAlertMessage = [NSString stringWithFormat: @"Already added."]; 
NSAlert *alert = [[[NSAlert alloc] init] autorelease]; 
[alert setAlertStyle:NSCriticalAlertStyle]; 
[alert addButtonWithTitle:@"OK"]; 
[alert setMessageText:theAlertMessage]; 
1

使用此为:

NSAlert *alert = [[NSAlert alloc] init]; 
[alert setAlertStyle:2]; 
[alert setMessageText:@"Already added"]; 

    [alert beginSheetModalForWindow:[(AppDelegate *)[[NSApplication sharedApplication] delegate] window] 
        modalDelegate:self 

        didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) 
        contextInfo:nil]; 
} 

- (void)sheetDidEnd:(NSAlert *)alert 
       returnCode:(int)returnCode contextInfo:(void *)contextInfo 
{ 
    NSLog(@"clicked %d button\n", returnCode); 

} 

希望它可以帮助你。