我环顾四周看了看其他的答案,但似乎没有什么对我的案子有帮助。
我有一个viewController类,它包含一个按钮的IBAction。此按钮应将NSOpenPanel作为来自该viewController的工作表打开:
class ViewController: NSViewController {
@IBAction func folderSelection(sender: AnyObject) {
var myFiledialog: NSOpenPanel = NSOpenPanel()
myFiledialog.prompt = "Select path"
myFiledialog.worksWhenModal = true
myFiledialog.allowsMultipleSelection = false
myFiledialog.canChooseDirectories = true
myFiledialog.canChooseFiles = false
myFiledialog.resolvesAliases = true
//myFiledialog.runModal()
myFiledialog.beginSheetModalForWindow(self.view.window!, completionHandler: nil)
var chosenpath = myFiledialog.URL
if (chosenpath!= nil)
{
var TheFile = chosenpath!.absoluteString!
println(TheFile)
//do something with TheFile
}
else
{
println("nothing chosen")
}
}
}问题来自于myFileDialog.beginSheetModalForWindow(..),它适用于上面的一行,但这不是工作表效果
发布于 2020-01-16 15:14:21
Swift 5
let dialog = NSOpenPanel()
dialog.beginSheetModal(for: self.view.window!){ result in
if result == .OK, let url = dialog.url {
print("Got", url)
}
}https://stackoverflow.com/questions/29596360
复制相似问题