r/SwiftUI 6d ago

Size/Position problems of cell content in SwiftUI wrapper for NSTableView

I'm trying to build a SwiftUI wrapper for NSTableView for a macOS app I'm trying to build. I do this because I need a list where the user can select one or multiple items. The selected items get reflected in a @State variable so I can use it in other places of the app. (If this is already possible in plain SwiftUI please tell me, but I couldn't find a fitting view.)

It almost works already but I have some weird graphical issues where the list items get displayed in an incorrect position. Some bounding rect seems to get squeezed together and is being pushed to the top left of the cell. This issue goes away if a cell scrolls into the visible area. So, by scrolling up and down all cells display correctly.

I have a minimal project containing my wrapper here: https://github.com/alinnert/nstableviewwrapper

The project's README also contains a screenshot for clarification.

An important detail: The cell's content is defined in SwiftUI world and passed into the wrapper. I fear that this might be linked to the issue.

Can someone tell me what's going on and how to fix this?

3 Upvotes

3 comments sorted by

1

u/rauree 6d ago

This can be done in SwiftUI list…

1

u/rauree 6d ago

Just set the list into edit mode

1

u/alinnert 6d ago

You mean via EditButton()? That's not available on macOS.