单击按钮后,我使用以下代码
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);
但是单击此警报的“确定”按钮后。我的警报仍然显示在屏幕上。请帮忙!
最佳答案
使用它作为:
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);
}
希望对您有帮助。
关于macos - Mac 应用程序中的“确定”警报按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6661408/