TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Getting rid of two chevrons from navigation link

Forums > SwiftUI

So I have two views I want to display depending on the user's choice. It works, the app takes me to where I want to go but I get two chevrons on the PatternView.

I tried to change the list to a section, that stopped the navigation completely. I tried some modifiers on the Navigation Link .Buttonstyle(.plain) and .listStyle(.plain)

Any suggestions?

The body looks like this

var body: some View {
        NavigationStack(path: $paths) {
            if dataController.selectedFilter == .allYarn || dataController.selectedFilter == .favoriteYarn || dataController.selectedFilter == .recentYarn {
                yarnBody
            } else {
                patternBody
            }
        }
    }

The yarnBody:

var yarnBody: some View {
        List(selection: $dataController.selectedYarn) {
            ForEach(dataController.yarnForSelectedFilter()) { yarn in
                YarnRow(yarn: yarn)
            }
            .onDelete(perform: deleteYarn)
        }
        }

The patternBody

var patternBody: some View {
        List {
            ForEach(dataController.patternForSelectedFilter()) { pattern in
                NavigationLink(value: Path.pattern(pattern)) {
                    PatternRow(pattern: pattern)
                }
                .buttonStyle(.plain)
            }
            .onDelete(perform: deletePattern)
        }
        .navigationDestination(for: Path.self) { path in
            switch path {
            case .pattern(let pattern):
                PatternView(pattern: pattern)
            }
        }
}

   

I not sure what you mean by two chevrons and I can not as do not know the dataController etc (too many errors when just putting the code in, However if you do not want the chevron which is a built behevior for NavigationLink in List. You could try a Button Did this small code to show

struct ContentView: View {
    @State private var paths = NavigationPath()
    @State private var selectedFilter = false

    let yarns = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    let patterns = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    var yarnBody: some View {
        List {
            ForEach(yarns, id: \.self) { yarn in
                Text("Yarn \(yarn)")
            }
        }
    }

    var patternBody: some View {
            List {
                ForEach(patterns, id: \.self) { pattern in
                    // USE BUTTON INSTEAD OF NAVIGATIONLINK
                    Button {
                        paths.append(pattern)
                    } label: {
                        Text("Pattern \(pattern)")
                    }
                    .buttonStyle(.plain)
                }
            }
            .navigationDestination(for: Int.self) { pattern in
                Text("PATTERN \(pattern)")
            }
    }

    var body: some View {
        NavigationStack(path: $paths) {
            if selectedFilter {
                yarnBody
            } else {
                patternBody
            }
        }
    }
}

   

This is what I meant by two chevrons. I will try it with the buttons and hopefully that will go away.

Update: This worked perfectly thank you so much.

   

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.