gpt4 book ai didi

macos - 将复选框添加到 NSOpenPanel

转载 作者:行者123 更新时间:2023-12-03 16:16:04 27 4
gpt4 key购买 nike

我想向NSOpenPanel添加一个复选框,然后在接收所选文件时查询其状态。我怎样才能做到这一点?

此外,希望能够根据当前文件选择启用或禁用该复选框。

最佳答案

基于 Joshua Nozzi 和 Mark Alldrit 答案的完整解决方案:

NSOpenPanel* openDlg = [NSOpenPanel openPanel];
NSButton *button = [[NSButton alloc] init];
[button setButtonType:NSSwitchButton];
button.title = NSLocalizedString(@"I am a checkbox", @"");
[button sizeToFit];
[openDlg setAccessoryView:button];
openDlg.delegate = self;
[openDlg beginSheetModalForWindow:self.window completionHandler:^(NSInteger result)
{
openDlg.delegate = nil; // TODO: Check if this is necessary
if (result != NSFileHandlingPanelOKButton) return;
BOOL checkboxOn = (((NSButton*)openDlg.accessoryView).state == NSOnState);
// Do something
}];

NSOpenSavePanelDelegate:

- (void)panelSelectionDidChange:(id)sender {
NSOpenPanel *panel = sender;
NSButton *button = (NSButton*)panel.accessoryView;
// Update button based on panel selection
}

关于macos - 将复选框添加到 NSOpenPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12940613/

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