如何设置 NSPathComponentCell 的 URL?
How to set the URL of a NSPathComponentCell?
我的设置屏幕中有几个 NSPathControl。我希望能够从 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?这是正确的方法吗?
- 如果要显示有效的URL,只需将
NSPathControl
实例的URL
属性设置为NSURL
对象
- 如果要显示相对路径或者其他无效的URL,看苹果示例代码NSPathControl Basics
我的设置屏幕中有几个 NSPathControl。我希望能够从 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?这是正确的方法吗?
- 如果要显示有效的URL,只需将
NSPathControl
实例的URL
属性设置为NSURL
对象 - 如果要显示相对路径或者其他无效的URL,看苹果示例代码NSPathControl Basics