0

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!

Mobile Ben
  • 7,121
  • 1
  • 27
  • 43
  • How about `NSOutlineView`? – Willeke Aug 05 '19 at 07:55
  • I'll look into this. My one concern is that the "expanded" view becomes another cell and in reality, the parent and child should be treated as one. So, for example, it should still be draggable as a single unit. – Mobile Ben Aug 05 '19 at 15:01
  • 1
    In outline views, dragging the parent cell drags all of the child cells as well (though you'd need to block child cells from being dragged out of their parents: easy enough). You could put a stack view inside a table cell, sure, but aside from the 'cool' factor I don't see any advantage you'd get by doing so. You'd just be reinventing the wheel, – Ted Wrigley Aug 05 '19 at 16:00
  • @TedWrigley thanks for the explanation. I'll check it out later today. I actually have both cases above working. `NSStack` view is a little hackier than expanding the `NSTableCelllView` as I essentially tag the second view as hidden in the completion block of `NSAnimationContext` when shrinking and immediately set `isHidden` to true prior to the case of expansion. – Mobile Ben Aug 05 '19 at 21:04
  • Hmm, in actuality, `NSOutlineView` is far more tedious. At least based on my nascent usage of it. There are a few reasons for this. 1. From what I can tell items effectively become identifiers for data. So if I have a top and bottom half of the same data, I need to actually create 2 objects so I can return them to the outline view, 2. In my case, disclosures are custom and would be placed elsewhere, so they need to be disabled, 3. An expanded cell and parent needs to be treated as one. Which also means, if highlighting is supported, both parent and child should be highlighted. – Mobile Ben Aug 06 '19 at 01:08
  • Once you expand a child, it's treated as a new row in the table. So it's a bit harder to track the rows. Doable, and I'll probably try and track it down later today. But based on these, it makes me feel this is the wrong tool for the job. Interesting to do the experiment however. – Mobile Ben Aug 06 '19 at 01:09

1 Answers1

0

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.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Mobile Ben
  • 7,121
  • 1
  • 27
  • 43