1

I have an app that has a navigationLink from one view to another, but when the NavLink moves to the second view, the NavigationTitle of that view is pushed, down, it's not inline. Is there any way to combine the toolbar and the title? I put my code below.

import SwiftUI

struct FirstView: View {
    var body: some View {
        NavigationView {
            Text("My Stuff")
                .toolbar {
                    ToolbarItem(placement: .navigationBarTrailing){
                        NavigationLink(destination: SettingsView(), label: {
                            Image(systemName: "gear")
                                .font(.system(size: 25))
                                .navigationTitle("My Stuff")
                        })
                        
                        
                      
                    }
                    
                    
            }
        }
    }
}

And the second view:

import SwiftUI

struct SettingsView: View {
    
    var body: some View {
        NavigationView {
            VStack {
                Text("Settings View")
                    .navigationTitle("Settings")
                
            }
        }
    }
}

A photo below of what is happening:photo of problem

Thank you for your help.

  • You should show your code. It sounds like you may be duplicating `NavigationView`. Or, you're looking for https://developer.apple.com/documentation/swiftui/view/navigationbartitledisplaymode(_:), but I'm unclear of which (or both). – jnpdx Apr 06 '22 at 22:55
  • Thank you; I put in my code. I tried changing the `navigationBarTitleDisplayMode` to .inline, but it still displays below the back button. –  Apr 06 '22 at 23:03
  • 1
    My suspicion was correct -- you have multiple `NavigationView`s. Get rid of the one in `SettingsView` – jnpdx Apr 06 '22 at 23:10

1 Answers1

0

jnpdx solved this... the solution was that I had an extra NavigationView in my SettingsView. I only needed one NavigationView.