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      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.