我正在努力在NSPathControl将文件或文件夹放到文件夹或文件夹之后检索文件夹或文件的POSIX路径.
我是初学者,但我能够通过Destination这种方式从我的代码中获取控件(被调用)的值:
NSString *filepath;
filepath = [Destination stringValue];
Run Code Online (Sandbox Code Playgroud)
这给了我类似的东西
file://test/My%20New%20Project/
但我希望以POSIX路径形式:
/test/My New Project因为我需要将它传递给
NSTask正在运行的命令行程序.
有关如何将此内容NSString从URL格式转换为POSIX路径的任何建议?
从Apple的示例代码和阅读文档中我看不出配置NSPathControl行为类似于例如Xcode Editor窗口中的" 跳转条 ":

即它代表一个路径(或其他类型的层次结构),并使路径的每个组件成为一个可点击的弹出窗口来导航层次结构..?
有人通过NSPathControlDelegate听取点击并在临时窗口中显示菜单来运气这样的行为吗?
看起来像一个普通的设计,人们甚至期望一些OSS实现 - 但没有这样的运气,但谷歌搜索它..
Apple将NSPathControl改为与Yosemite中的NSPathControlItem一起使用.
但是从我所在的地方来看,这些新课程根本不起作用.我试图在我的数据结构中显示自定义路径,但我有一个常规文件路径的类似问题.是我还是Apple?
这是我的代码:
第一个代码段工作,它将显示一个路径.但这就是一切有效.
//MARK: notifications
func selectionDidChange(notification : NSNotification)
{
if let item = notification.object as? Group
{
//get "path" components
var components : [String] = [item.title ?? "a"]
var ancestor : Group? = item.parent
while (ancestor != nil)
{
components.append(ancestor?.title ?? "b")
ancestor = ancestor?.parent
}
components.append("")
//convert to url
let path = ("MyScheme:/" + "/".join(components.reverse()))
pathControl?.URL = NSURL(string: path.stringByAddingPe
}
}
Run Code Online (Sandbox Code Playgroud)
单击路径的任何部分以尝试从NSPathControlItem中获取任何属性根本不起作用.一切都归零.
@IBAction func select(sender : AnyObject)
{
println(sender.clickedPathItem??.title)
println(sender.clickedPathItem??.URL)
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用NSPathControlItem构建路径,则无法设置任何属性(title,url).
pathComponent.URL = NSURL(string: path.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)
//let …Run Code Online (Sandbox Code Playgroud)