我的设置屏幕中有几个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传递什么?这是正确的方法吗?
答案 0 :(得分:2)
URL
对象设置NSPathControl
实例的NSURL
属性