Macos mac应用程序中警报的“确定”按钮不起作用
点击一个按钮,我使用下面的代码Macos mac应用程序中警报的“确定”按钮不起作用,macos,cocoa,cocoa-sheet,Macos,Cocoa,Cocoa Sheet,点击一个按钮,我使用下面的代码 testViewController *myWindowController = [[testViewController alloc] initWithWindowNibName:@"RecordingsViewController"]; [myWindowController setDelegate:self]; activeModalWindow = [myWindowController window]; [NSApp beginSheet:[myW
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);
但单击此警报的“确定”按钮时。我的警报仍在屏幕上。请帮忙 找到了一个替代方案,它可以完美地工作
NSString *theAlertMessage = [NSString stringWithFormat: @"Already added."];
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:theAlertMessage];
将此选项用作:
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);
}
希望它对您有所帮助。奇怪,这对我很有用,您在调试器控制台中是否有错误/警告消息?能否尝试使用NSRunAlertPanel使用简单框架构建新项目,以验证其在系统中的功能?(排除该问题仅存在于本项目中的可能性)