1
var body: some View {
    
    NavigationView{
        ZStack(alignment: .leading){
            
            ZStack(alignment: .top){
                VStack{
                    HStack(alignment: .top) {
                        Image(systemName: "chevron.left")
                            .font(.title2)
                        Text("profile")
                            .fontWeight(.bold)
                        
                        Spacer()
                        
                        Button(action: {
                            

                        }) {

                            Image(systemName: "person.crop.circle.fill.badge.plus")
                                .resizable()
                                .aspectRatio(contentMode: .fit)
                                .frame(height: 24)
                            
                            Text("subscribe")
                            
                            Button(action: {

                            }) {
                                Image("share_black_24dp")
                                    .tint(Color.white)
                                    .foregroundColor(Color.white)
                            }
                            
                            
                            
                        }
                        .foregroundColor(Color.white)

                    }
                    .frame(width: UIScreen.main.bounds.width - 20, height: 40)
                    .padding(.horizontal, 20)
                    .background(Color.teal)
                    
                }

                // .navigationBarItems(leading: backButton)

                ScrollView(.vertical, showsIndicators: false){
                    
                }
                
            }
        }
        .navigationBarTitle("")
        .navigationBarHidden(true)
        .navigationBarBackButtonHidden(true)
    }
}

where does

    .navigationBarTitle("")
    .navigationBarHidden(true)
    .navigationBarBackButtonHidden(true)

need to be!?

I also tried it for NavigationView and it doesn't work

vacawama
  • 150,663
  • 30
  • 266
  • 294
IHateGoogle
  • 105
  • 10
  • 1
    Which back button are you referring to? Your code is drawing a left arrow (chevron) and the word profile, but that isn't a back button. If I remove your three .navigationBar lines, extra space appears, so they are doing their job. Is this your root view, or are you coming here from another view? – vacawama Sep 03 '22 at 00:36
  • @vacawama Sounds like a common mistake of nested `NavigationView`s to me too – George Sep 03 '22 at 00:49
  • yes I'm coming to this view from the main view and I want the toolbar to be the way I create it and not some forced default crap. Besides the entire navigationview/link is beyond dumb, why can't they do it like android, why does apple need to do everything needlessly complicated – IHateGoogle Sep 03 '22 at 00:53
  • Only the first view should have a NavigationView. If your main view has a NavigationView, then don't add a second one here. – vacawama Sep 03 '22 at 01:05
  • Oh ok so I can use navigationlinks in the child view then without it also having navigationview? That makes sense, thanks! I'll check if you create it as answer but I'll do it tomorrow because I'm off for today – IHateGoogle Sep 03 '22 at 01:09

1 Answers1

2

Your issue is that you have multiple NavigationViews.

NavigationView creates a new stack of views. Only your main view should have a NavigationView. The child views can use NavigationLink to push new views, but they should not create another NavigationView.

Think of it like this. NavigationView creates that stack to hold the views, and NavigationLink pushes a new view onto the stack. You only want to create one stack.

So, get rid of NavigationView in your View above, because it is linked from the main view which creates the NavigationView. Then, your code to hide the navigation bar will work as you expect.

vacawama
  • 150,663
  • 30
  • 266
  • 294