0

I got 2 views. On the second view I have list of exercises and when I choose one of them and go inside I see double back. It's driving me crazy.

First one:

import SwiftUI

struct ProgrammView: View {
    var body: some View {
        
        NavigationView{
            ScrollView(.vertical, showsIndicators: false) {
            VStack {
                Text("blabla")
                    .multilineTextAlignment(.center)
                    .font(.custom("AvenirNext-Bold", size: 30))
                NavigationLink{
                    InsultHandProgram()
                    
                } label: {
                    Image("35")
                        .resizable()
                        .scaledToFit()
                        .padding(.horizontal)
                        .padding(.bottom, 7)
                        .shadow(radius: 5)
                }                  
            }
        }
    }
}
}

Second one:

import SwiftUI

struct InsultHandProgram: View {
    let numbers = InsultProgram.getInsultProgram()
    var body: some View {
        NavigationStack {
            List(numbers) { InsultProgram in
                NavigationLink( InsultProgram.name, value: InsultProgram)
            }
            .navigationTitle("blabla")
            .navigationDestination(for: InsultProgram.self) {
                InsultProgram in InsultProgrammDetail(InsultProgram: InsultProgram)
            }
        }
    }

enter image description here

I tried to change navigation stack. It's crushed.

stackich
  • 3,607
  • 3
  • 17
  • 41

1 Answers1

0

If you use NavigationView, then it provides the navigation bars for all its child views. NavigationStack in your child view also wants to provide a navigation bar, and so you end up with two.

To remedy the situation you have some choices:

  1. Remove the NavigationStack from your child view and let NavigationView manage everything.
  2. Remove NavigationStack from you child view and replace NavigationView in your parent with a NavigationStack. This will work fine on iPhones, but doesn't adapt well to iPads.
  3. Keep your navigation stack in the child view but replace NavigationView with NavigationSplitView. This came in with iOS16, as did NavigationStack. The two work well together so they don't step on each other's toes when it comes to setting up navigation bars.

Given you're already using other iOS 16 idioms such as navigationDestination I'd recommend approach 3.

ScottM
  • 7,108
  • 1
  • 25
  • 42