2

I have an application I'm developing in cocoa, and I have a problem with NSPathControl.

I set the style of the control to Popup, and when I launch my App and click on the path control, it shows me a popup menu with the components of the URL I set. I.e., for URL like file://localhost/Applications/Games/ it shows me the following: My Macbook, Macintosh HD, Applications, Games.

Now, when I click on Applications, I receive an action, and whithin that action [[sender clickedPathComponentCell] URL] returns correct URL: file://localhost/Applications/.

Problem 1: But when I click on Macintosh HD, I get an URL with double trailing slash: file://localhost//.

Problem 2: is that I get the same URL file://localhost// when I click on My Macbook item. So, I have 2 questions:

  1. Why does the URL to Macintosh HD ends with double slash?

  2. How can I distinguish clicks on Macintosh HD and My Macbook, and what is the correct URL to My Macbook, where Finder shows the list of mounted volumes (on my macbook it is Macintosh HD and BOOTCAMP)?

I've examined the tutorial named "SourceView", but there was no item like My Macbook, so I was not able to find out, whether My Macbook is really exists as a some kind of virtual folder, or I should just use NSFileManager to get the list of mounted volumes.

4

1 回答 1

1

问题 1:

该 URL 是file://localhost//因为引导卷的路径是/. 这有点奇怪,但是file://localhost/(single slash) 表示“本地主机上没有路径的文件”,所以你得到file://localhost//(双斜杠) 表示“本地主机上的文件 path /

你真的不必担心你得到的 URL 的怪癖 - 只需将它传递给任何需要它的东西,它应该可以很好地处理它。

问题2:

“我的 MacBook”实际上并不存在 - 它是一个显示已连接卷列表的虚拟文件夹/Network,等等。由于它不存在,因此它没有有效的路径,因此您可以获得引导路径而是音量。

于 2012-05-22T17:30:35.970 回答