2015-07-11 57 views
0

我在我的設置屏幕中有幾個NSPathControls。我希望能夠從NSUserDefaults中檢索存儲的設置,並用存儲的URL初始化NSPathControl的NSPathComponentCell。如何設置NSPathComponentCell的URL?

目前,我有以下代碼:

class SettingsViewController: NSViewController { 

    let userDefaults = NSUserDefaults.standardUserDefaults() 

    var designFolderPath:String = String() 
    var developmentFolderPath:String = String() 

    @IBOutlet weak var designFolder: NSPathControl! 
    @IBOutlet weak var developmentFolder: NSPathControl! 

    @IBAction func saveUserSettings(sender: AnyObject) { 
     saveUserSettings() 
    } 

    func saveUserSettings() { 
     designFolderPath = designFolder.URL!.absoluteString 
     developmentFolderPath = developmentFolder.URL!.absoluteString 


     userDefaults.setObject(designFolderPath, forKey: "designFolder") 
     userDefaults.setObject(developmentFolderPath, forKey: "developmentFolder") 

     dismissController(self) 

    } 


    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do view setup here. 

//  let designFolderURL:NSURL = NSURL(fileURLWithPath: designFolderPath, isDirectory: true) 
//  designFolder.setPathComponentCells(NSPathComponentCell.URL(designFolderURL, resourceDataDidBecomeAvailable: <#T##NSData#>)) 

    } 

    override func viewDidDisappear() { 

    } 

} 

在viewDidLoad中註釋掉線()方法,我試圖用一個URL來初始化NSPathComponentCell,但我不知道該怎麼傳爲NSData的?這是正確的方法嗎?

回答

2
  • 如果你想顯示一個有效的網址,只需設置NSPathControl實例的URL財產與NSURL對象
  • 如果你想顯示相對路徑或無效的網址,看看蘋果的示例代碼NSPathControl Basics