Embedding NSStackView as NSTableCellView in NSTableView

那年仲夏 提交于 2019-12-13 06:31:42

问题


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:

  • Expanding NSTableViewCell
  • Using an NSStackView as the contents of each cell

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

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

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.

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.

Thanks!


回答1:


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.

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.

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.

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.



来源:https://stackoverflow.com/questions/57351965/embedding-nsstackview-as-nstablecellview-in-nstableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!