gpt4 book ai didi

objective-c - 如何在 OSX 上自动关闭 NSAlert?

转载 作者:搜寻专家 更新时间:2023-10-30 19:57:49 27 4
gpt4 key购买 nike

我想创建 NSAlert(弹出)显示然后自动关闭。同样点击 Button,它显示弹出窗口 Scanning...,在找到任何项目后,弹出窗口 Scanning auto dismiss。当弹出窗口显示时,用户无法单击我的应用程序上的任何按钮。我怎样才能做到这一点?非常感谢。

最佳答案

下面的代码可以帮到你

- (IBAction)showAlert:(id)sender {
//display the alert
self.myAlert = [NSAlert alertWithMessageText:@"Sample Test" defaultButton:@"OK" alternateButton:@"DO Nothing" otherButton:@"CANCEL" informativeTextWithFormat:@"TEST",nil];
[self.myAlert beginSheetModalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(errorAlertDidEnd:returnCode:contextInfo:)
contextInfo:nil];

NSArray *buttonArray = [self.myAlert buttons];
NSLog(@"Button Arrays %@",buttonArray);

//Close by itself without a mouse click by the user
//Assuming the Default Button as the Second one "Do Nothing
NSButton *myBtn = [buttonArray objectAtIndex:2];
[myBtn performClick:self.myAlert];

关于objective-c - 如何在 OSX 上自动关闭 NSAlert?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18460060/

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