-2

I have this problem while working with SwiftUI. So basically, when I press on the navigation link, it opens the screen like this:Picture 1

and because of this, the whole thing below that is pushed lower. And then, when I press to the navigation link from this screen, the result is this:

Picture 2

so it goes even lower and creates the second "back" button.

How do I get rid of this "padding" created by the "back" button?

The way I did the navigations:

    var body: some View {
        NavigationView {
            ZStack {
                Text("Hi")
            }
        }
    }
}
teheheugh
  • 7
  • 4
  • 4
    You are certainly using repeated/ nested `NavigationView` lines and not hiding the navigation title. But without a piece a code, it's hard to say more. [This link](https://stackoverflow.com/help/minimal-reproducible-example) will help you improve your question. – HunterLion May 07 '22 at 12:21
  • Make sure there is only one NavigationView sitting at the bottom of the view hierarchy – Saket Kumar May 07 '22 at 12:58
  • 1
    Related to https://stackoverflow.com/questions/71774468/combine-navigationtitle-and-navigation-back-button-swiftui –  May 07 '22 at 16:21
  • 1
    Please provide a [Minimal Reproducable Example](https://stackoverflow.com/help/minimal-reproducible-example) so that the community can both reproduce your code and suggest improvements. –  May 07 '22 at 16:25

1 Answers1

1

Your issue is that you have duplicate NavigationViews. There are two ways to solve this:

  1. When you call the next view in your NavigationLink, set .navigationBarBackButtonHidden(true). This will disappear the extra back button.

  2. A simpler way; just delete the NavigationView in your second view (the linked one). That will prevent duplicate back buttons.

  • 1
    thank you so much! your comments and your answer helped me. i'm just a bit confused with the transportation between the screens, just switched to swiftui after uikit. thank you! – teheheugh May 08 '22 at 01:51
  • 1
    Glad to be of help. –  May 08 '22 at 01:57