如何设置NSPathComponentCell的URL?

时间:2015-07-11 18:05:14

标签: macos swift cocoa foundation nspathcontrol

我的设置屏幕中有几个NSPathControls。我希望能够从NSUserDefaults检索存储的设置,并使用存储的URL初始化NSPathControl的NSPathComponentCell。

目前我有以下代码:

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传递什么?这是正确的方法吗?

1 个答案:

答案 0 :(得分:2)

  • 如果要显示有效的网址,只需使用URL对象设置NSPathControl实例的NSURL属性
  • 如果您想显示相对路径或其他无效网址,请查看Apple示例代码NSPathControl Basics