与 NSBrowser 相比,NSBrowserTableView 是什么?

发布于 2024-10-06 19:04:30 字数 413 浏览 2 评论 0原文

我正在实现一个 -(void)delete: 方法,这样我就可以在我的 Cocoa 应用程序中处理删除键。我希望它根据所选内容执行不同的操作:对于文本字段,我想要默认行为(删除左侧的字符),但对于 NSBrowser 项目,我希望它删除该项目。

我想我应该向 Window 询问它的第一响应者,然后查看该第一响应者是否等于我的 NSBrowser 的指针,但它从未匹配。当我调试它时,我发现firstResponder指向NSBrowserTableView的实例,但我在文档中找不到它。

它是什么?

我还能如何测试我的firstResponder是否是特定的tableView? (我想过对 NSBrowser 进行子类化,但我倾向于避免子类化,我的第二个想法是添加一个标签,但我最喜欢我的第一个方法,只要当浏览器中的一个项目是已选择)的

想法?

I'm implementing a -(void)delete: method so I can handle the delete key in my Cocoa app. I want it to do different things depending on what's selected: for text-fields, I want the default behaviour (remove char to the left), but for NSBrowser items, I want it to delete the item.

I thought I would ask the Window for it's first responder, and then see if that first responder is equal to the pointer for my NSBrowser, but it never matched. When I debug it, I find that the firstResponder is pointing to an instance of NSBrowserTableView, but I can't find that in the documentation.

What is it?

And how else could I test to see if my firstResponder is a particular tableView? (I Thought of subclassing NSBrowser but I tend to avoid subclassing, and my second thought was to add a tag, but I like my first method best, if only the firstResponder would point to my NSBrowser instance when one of the items in the browser is selected. )

Thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宣告ˉ结束 2024-10-13 19:04:30

实际上,@trudyscousin 仅部分正确。这个类绝对不是 NSBrowser 的子类。

NSBrowserTableView 是 NSTableView 使用的私有子类NSBrowser 显示每一列。使用表视图,因此有一个单独的位置来绘制分支图像(文件夹旁边绘制的小箭头),同时保留行的其余部分由默认或用户定义的单元格绘制。

如果您考虑一下,表视图(而不是浏览器)成为第一响应者实际上是有道理的,因为这样活动列的表就会首先响应击键,并且 NSBrowser 可以让 NSTableView 做它已经做的事情知道如何做。 (例如,跳转到与用户键入的字母匹配的第一行。)

幸运的是,NSBrowserTableView 有一个指向它所适用的浏览器的指针。您可以通过其 -(NSBrowser*)browser 方法访问它。我建议您不要在这种特殊情况下子类化 NSBrowser,因为您必须深入了解其私有实现才能执行任何有用的操作。

Actually, @trudyscousin is only partially correct. This class is definitely not a subclass of NSBrowser.

NSBrowserTableView is a private subclass of NSTableView used by NSBrowser to display each column. The table view is used so there is a separate place to draw the branch image (the little arrow drawn next to folders) while leaving the rest of the row to be drawn by either the default or user-defined cell.

If you think about it, it actually makes sense that the table view (rather than the browser) be the first responder, because then the table for the active column gets first crack at responding to keystrokes, and NSBrowser can let NSTableView do what it already knows how to. (For example, jumping to the first row that matches a letter typed by the user.)

Fortunately, NSBrowserTableView has a pointer back to the browser it works for. You can access this via its -(NSBrowser*)browser method. I recommend you don't subclass NSBrowser for this particular case, since you'd have to have a deep knowledge of its private implementation to do anything useful.

荒人说梦 2024-10-13 19:04:30

您无法在文档中找到它,因为它是私有的。我的猜测是,当你实例化 NSBrowser 或 NSTableView 时,你实际上是实例化这个私有类的子类,它本身就是 NSControl 的子类(在文档中指出它是NSBrowser 和 NSTableView 的超类)。另一个例子是 NSString 表示为“NSCFString”,我将其视为暗示 CFString 和 NSString 是“免费桥接”这一事实。

你可以对此持怀疑态度,但我要深入了解第一响应者的方法是在我的代码中插入一条 NSLog 语句,然后突破它,查看日志中打印的内容。您可以设置视图的标签并将其显示在语句中。或者您可以询问第一个响应者的类别

NSStringFromClass([myFirstResponder class]) 

并显示该类别。

希望这有帮助。

You can't find that in the documentation because it's private. My guess is that, when you instantiate a NSBrowser or a NSTableView, you're actually instantiating a subclass of this private class, which itself is a subclass of NSControl (which is pointed out in the documentation as being the superclass of both NSBrowser and NSTableView). Another example is NSString represented as 'NSCFString,' which I take as an allusion to the fact that CFString and NSString are "toll-free bridged."

Take this with as many grains of salt as you wish, but the way I'd go about gaining insight into the first responder is inserting a NSLog statement in my code and breaking just beyond it, seeing what was printed in the log. You could set the view's tag and display that in the statement. Or you could ask for your first repsponder's class

NSStringFromClass([myFirstResponder class]) 

and display that.

Hope this helped.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文