Table view with dynamic content - is it possible?

Hi,

How can I use a Table view to build a data grid for a dynamic set of data?

Say, I have a 2D collection of data elements (a matrix, basically) with variable number of columns, and a 1D collection of column labels (a vector). For the sake of simplicity, let's assume that all data elements are Strings.

let data: [[String]]; let columnLabels: [String]

How can I build TableColumn definitions without key paths?

Thanks!

Do you want to do this in UIKit or in SwiftUI ?

Or is it MacOS ? In that case, that's much easier.

Multicolumns table are not easy with TableViews. You'd probably better use CollectionView.

See also if UIKit: https://developer.apple.com/documentation/uikit/uicollectionview?changes=_4

I was hoping to use the new Table view in SwiftUI on Mac OS.

@Claude31, you mentioned that it's much easier in MacOS? Do you mind sharing more details on this, please? Thanks!

In case anyone has the same question, I couldn't make the new TableView work with dynamic data source. Then I tried constructing a bunch of TextFields dynamically in a grid. It kind of worked, but it was very sluggish when scrolling. So I ended up wrapping NSTableView in NSViewRepresentable and working directly with NSTableView APIs. Performance is great with NSTableView and NSTextField as a cell view.

The function of SwiftUI Table component can hardly be extended. It is basically a toy.

Table view with dynamic content - is it possible?
 
 
Q