使用NSOutlineView作为文件浏览器,从给定的目录开始 [英] Using NSOutlineView as a file browser, starting from a given directory

查看:295
本文介绍了使用NSOutlineView作为文件浏览器,从给定的目录开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用NSOutlineView作为层次文件浏览器的本教程:

I've been following this tutorial for using NSOutlineView as a hierarchical file browser:

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/OutlineView/Articles/UsingOutlineDataSource .html

我使用了教程中的所有代码,它工作。然后,我然后尝试调用 initWithPath:使用除 / 之外的路径,它不工作:顶部项目(即 initWithPath 中指定的文件夹)的code> fullPath 只是文件夹的名称,<$ 方法返回一个空数组,我假设因为文件管理器正在查找 /

I used all the code in the tutorial and it worked. However, I then tried to call initWithPath: with a path other than / and it doesn't work: the fullPath of the top item (i.e. the folder specified in initWithPath) is just the name of the folder, and the children method of the FileSystemItem returns an empty array, I assume because the file manager is looking in /FolderName/ rather than the absolute path, which never appears to be saved.

如何修改此代码以允许它执行此操作?

How could I modify this code to allow it to do this?

推荐答案

上面的代码几乎可以工作。一旦你试图打开一个文件夹它崩溃。尝试这个修改。它为我工作完美:

The code above almost works. As soon as you try to open a folder it crashes. Try it with this modification. It works perfectly for me:

- (id)initWithPath:(NSString *)path parent:(FileSystemItem *)parentItem {
  if (self = [super init]) {
    relativePath = [path copy];
    parent = parentItem;
  }
 return self;
}

这篇关于使用NSOutlineView作为文件浏览器,从给定的目录开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆