【发布时间】:2015-10-08 08:08:47
【问题描述】:
我想知道如何通过首先通过 NSOpenPanel 获取文件来填充 NSTableView。这就像我在运行时从文件夹中选择后列出/显示文件一样。
编辑:所以我有这种工作(通过绑定)....但是除非我单击表格顶部,否则我无法显示它。如果您打开以获取更多文件,则显示将不会再次更新。
我觉得这可能是因为 controllerArray 的 Received Action add: 没有链接。 下面的代码就是我现在所拥有的
@IBAction func openPanel(sender: NSButton) {
let openPanel = NSOpenPanel()
openPanel.allowedFileTypes = ["pdf"]
openPanel.canChooseFiles = true
openPanel.allowsMultipleSelection = false
openPanel.canChooseDirectories = true
openPanel.beginWithCompletionHandler { (result) -> Void in
if result == NSFileHandlingPanelOKButton {
var url:NSURL = openPanel.URL!
var pdfFile: PDFModel = PDFModel()
pdfFile.initWithURL(url)
self.insertFileLibrary(pdfFile, inFileListAtIndex: self.fileLibrary.count)
}
}
}
func insertFileLibrary(pdfModel:PDFModel, inFileListAtIndex index:Int){
fileLibrary.insertObject(pdfModel, atIndex: index)
}
func removeObjectFromFileLibraryAtIndex(index:Int){
fileLibrary.removeObjectAtIndex(index)
}
【问题讨论】:
-
如果你在 addToTable 中设置断点,fileList、table 和 doc 是你所期望的吗?
-
对不起,我没有关注....
标签: macos swift cocoa nstableview nsopenpanel