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