Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build an AppKit table view using SwiftUI?

We have got a lot of tutorials for iOS with code like this:

List(items) { item in
  NavigationLink(destination: ItemView(item: item)) {
    ItemRow(item: item)
  }
}

On macOS however, this code results in a list of disabled table cell views.

So how do we build something like NSTableView using SwiftUI?

like image 675
Vadim Avatar asked Oct 26 '25 14:10

Vadim


1 Answers

In order to use NavigationLink, you’ll need to be in a NavigationView context. Wrapping your current view hierarchy in a NavigationView should fix your issue.

NavigationView {
    List(items) { item in
      NavigationLink(destination: ItemView(item: item)) {
        ItemRow(item: item)
      }
    } 
}
like image 195
Dimillian Avatar answered Oct 29 '25 19:10

Dimillian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!