我正在使用NSOpenPanel
让用户选择如下文件:
NSOpenPanel *openPanel = [[NSOpenPanel alloc] init];
openPanel.canChooseFiles = YES;
openPanel.allowsMultipleSelection = NO;
openPanel.canChooseDirectories = NO;
openPanel.allowedFileTypes = @[@"mov", @"mp4"];
openPanel.allowsOtherFileTypes = NO;
[openPanel beginWithCompletionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
[self.editorWindowController loadVideoWithUrl:openPanel.URL];
}
}];
一切都很好,唯一的问题是,当您单击文件时,光标将设置为文本编辑模式,因此它会尝试重命名该文件。单击其他任何地方否则选择正常的行。感谢
答案 0 :(得分:2)
问题很简单,但很难找到。我有以下代码影响所有NSTableViews:
extension NSTableView {
override open func validateProposedFirstResponder(_ responder: NSResponder, for event: NSEvent?) -> Bool {
return true
}
}