在NSTableView中将NSStackView嵌入为NSTableCellView [英] Embedding NSStackView as NSTableCellView in NSTableView

查看:98
本文介绍了在NSTableView中将NSStackView嵌入为NSTableCellView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为Todo类型的应用开发原型.我有一个包含用户任务的表.我只想向用户提供相关的任务信息.但是要编辑其他信息,他们将单击显示"按钮以展开单元格.

I'm currently working on a prototype for a todo type app. I have a table which contains the user tasks. What I want to do is only present the user with pertinent task information. But to edit additional information, they would click on a disclosure button to expand the cell.

我在想两种可能的解决方法:

I was thinking of two possible ways to handle this:

  • 扩展NSTableViewCell
  • 使用NSStackView作为每个单元格的内容

如果使用NSTableViewCell,我可能会有两个NSViews代表单元格(顶部和下部).

If using the NSTableViewCell, I would probably have two NSViews to represent the cell (top part and lower part).

如果使用NSStackView,我将有一种简单的方法来封装零件.

If using the NSStackView, I'd have an easy means of encapsulating the parts.

我想另一种方法也可以是完全使用NSStackView来构建它.

I suppose another method could also be just building it entirely with NSStackView.

这更困难的方面似乎与单元格的实际扩展/折叠有关.

The more difficult aspect of this seems to be related to the actual expansion/collapse of the cell.

我知道这可以视为要求征求意见的问题类型.我从未构建过MacOS应用程序.因此,我正在寻找有关解决问题的最佳方法的指导,而不是只注定要无济于事的方法.

I understand this could be deemed the type of question that's asking for an opinion. I've never built a MacOS app. So I'm looking for some guidance as to the best method to approach the problem versus spinning my wheels on approaches that are destined to not be productive.

谢谢!

推荐答案

最后,看来最好的方法是使用NSTableCellView,上半部和下半部都带有两个NSView.我有这种情况,以及NSStackView工作.但最后,我发现使用NSStackView折叠或展开需要调用以使noteHeightOfRows始终正常工作.

In the end, it looks like the best thing to do is use an NSTableCellView with two NSViews for the top and bottom half. I had the case of this as well as the NSStackView working. But in the end, I found that using NSStackView to collapse or expand requires a call to make noteHeightOfRows work anyways.

因此,一开始似乎没有必要进行扩展,除非我有一个更复杂的单元格,例如我想要一个顶部,中间位置和底部,中间位置可以扩展和收缩.虽然我仍然需要使用noteHeightOfRows,但可以使用它.

So it would initially seem that it's not worth the effort of expanding it unless I have a more complicated cell where say I wanted a top, middle, and bottom, where the middle could expand and contract. While I would still need to use noteHeightOfRows, it would allow for it.

但是,使用NSStackView有一个好处.动画对于折叠更加平滑.我发现顶部和底部NSViewNSTableCellView方法在折叠时显示出撕裂"的迹象.这是在底部边缘出现的水平抖动现象.如果您向按钮发送垃圾邮件或选择了单元格,则尤其明显,因为轮廓的底部有时会变高.

However, there is one benefit of using the NSStackView. The animation is much smoother for the collapse. I've found the NSTableCellView method with a top and bottom NSView shows signs of "tearing" as it collapses. This is what appears in the bottom edge, while horizontal, jitters. This is particularly apparent if you either spam the button or if the cell is selected because the bottom of the outline can sometimes grow in height.

我还发现,使用NSAnimationContext帮助使其看起来更平滑时,我会看到奇怪的行为.就像皮革会在错误的时间发生(即使它在completionHandler中也一样.我认为根本原因是变成重叠的动画.

I also found that when using NSAnimationContext to help make it look a little smoother, I'd see strange behavior. Like the hide would happen at the wrong time (even though it was in the completionHandler. I think the root cause of that are what becomes overlapping animations.

这篇关于在NSTableView中将NSStackView嵌入为NSTableCellView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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