嗨,我有一个 NSStatusItem,单击时会显示一个弹出框。弹出窗口中的一个选项是删除某些内容;在这一点上,我问用户他们是否确定。
问题是一旦出现警报,弹出框就会自动关闭。
我已经尝试了所有不同的行为设置,例如NSPopoverBehaviorSemitransient
,NSPopoverBehaviorTransient
但NSPopoverBehaviorApplicationDefined
无济于事。
我也尝试将其捕获,- (BOOL)popoverShouldClose:(NSPopover *)popover
但是当 NSAlert 出现时不会调用它。
似乎没有什么能阻止 NSAlert 关闭弹出窗口。
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:msg];
[alert setInformativeText:@"Warning, delete this folder?"];
[alert setAlertStyle:NSCriticalAlertStyle];
// Show the alert
if ([alert runModal] == NSAlertFirstButtonReturn) {
我还尝试将警报显示为弹出窗口中的工作表,但无论我在它外部单击,弹出窗口都会保留。