gpt4 book ai didi

macos - Mac 应用程序中的“确定”警报按钮不起作用

转载 作者:行者123 更新时间:2023-12-03 18:00:48 24 4
gpt4 key购买 nike

单击按钮后,我使用以下代码

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com