UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

NavigationLink inside DisclosureGroup

Forums > macOS

Is it possible to get a NavigationLink to work with a subitem in a DisclosureGroup?

Not intened to be useful, the following is just an example of sort of something I want to do. The first navigation link works the second doesn't even show the navigation link.

Suggestions?

Example:

        List(selection: self.$selection) {

            NavigationLink(destination: ManuscriptView(name: "howdy")) {
                Label("Manuscript", systemImage: "book")
            }

            DisclosureGroup("Items", isExpanded: $topExpanded) {

                NavigationLink(destination: ManuscriptView(name: "howdy")) {
                    Toggle("Toggle 1", isOn: $toggleStates.oneIsOn)
                }

                ...

3      

I couldnt get that to work, but I found this example which does what I need with OutlineGroup instead:

    NavigationView {

        List() {

            ForEach(data) { dataValue in

                Section(header: EmptyView()) {

                    OutlineGroup(dataValue, id: \.id, children: \.children) { item in

                        NavigationLink(destination: ManuscriptView(name: item.description)) {
                            Text ("\(item.description)").padding(.all)
                        }
                    }
                }
            }
        }
        .listStyle(SidebarListStyle())
        .navigationTitle("Fruits & Vegitables")
    }

3      

@jfranknichols it is possible - just make sure you're implementing correctly the Identifiable protocol. Instead of doing:

let id = UUID()

Make the id property be something unique, that doesn't change, and is associated to some data of that line.

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.