NSOutlineView 设置最大列宽及其内容
是否可以设置 NSOutlineView 的 NSTableColumn 最大宽度及其内容?
提前致谢。
Is it posible to set an NSOutlineView's NSTableColumn max width with its contents?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
八个月后,我希望您继续选择一些足够好的宽度。然而,如果有人需要这种东西,这里有一个方法。它仍然有很大的局限性,所以请密切关注评论。
NSTableView 和 NSOutlineView 背后的整个理念是,它们在需要时才实例化其内容。这有利于效率,但意味着它们会主动阻止每个单元格的读取属性。要根据其内容调整列的大小,您确实必须查看每个单元格并测量其大小。这永远无法很好地扩展。
也就是说,如果您有一个非常小的 NSOutlineView,并且它都是文本,并且该文本来自数据源,那么这应该可以工作。
After eight months I hope you just went ahead and chose some widths that were good enough. However, if anyone needs this sort of thing, here is a method for the job. It still has significant limitations, so please pay close attention to the comments.
The entire philosophy behind NSTableView and NSOutlineView is that they don't instantiate their contents until needed. This is good for efficiency, but means that they actively discourage reading properties of every cell. To size a column to its contents, you really do have to look at every cell, and measure its size. This can never scale well.
That said, if you have a very small NSOutlineView, and it's all text, and that text comes from a dataSource, this should work.
关于选择足够好的宽度:我将
TableViewCell
的宽度设置为 10,000,这是 XCode/Cocoa 允许的最大值。这解决了项目在几个字符后被省略号截断的问题。我在导航器区域的
Table Column
对象的Table Cell View
项下选择了Table View Cell
。然后,在“实用工具区域”中,我选择了“尺寸检查器”,并将“视图”窗格中的“宽度”字段设置为 10,000。Regarding choosing widths that are good enough: I set the width of my
TableViewCell
to 10,000, which is the maximum that XCode/Cocoa allow. This fixed the problem of items being cut off with ellipses after a few characters.I chose the
Table View Cell
under theTable Cell View
item in theTable Column
object in the Navigator Area. Then, in the Utility Area, I selected the Size Inspector, and set the Width field in the View pane to 10,000.