2015-10-08 42 views
0

我想知道如何通過首先通過NSOpenPanel獲取文件來填充NSTableView。這就像在運行時從我的文件夾中選擇後列出/顯示文件。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) 
    } 
+0

如果你在addToTable中放置一個斷點,是fileList,table和doc你期望的是什麼? – Willeke

+0

對不起,我不關注.... – Sandy

回答

0

綁定使用志願,你必須變異fileLibrary在志願的方式由willChange包圍...和... didChange。讓NSArrayContoller這樣做更容易。您可以使用NSArrayController的addObject(s),insertObject(s)和removeObject(s)方法。