FREE TRIAL: Accelerate your app development career with 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)
                }

                ...

   

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")
    }

   

@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.

   

Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Get started

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

Reply to this topic…

You need to create an account or log in to reply.

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.