6
我环顾了其他答案,但似乎没有任何帮助我的情况。NSOpenPanel as
我有一个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(..),其工作原理与上面的行,但是这不是一个片效果
这就是它!谢谢! @ericd – OrangePot