0

I followed this tuto : https://www.youtube.com/watch?v=mUMR5TCqpDU

Until the end it's ok. But now I would like to add a button.

So I created : bouton1 and 2 at the top

And this is the header of my page : headerview

I would like to go on another view when I click on Bouton2 for example. I guess it's a basic functionality, BUT I when I add navigationview that change everything on my page..

I guess it's because I have a header that should be different..

I tried with

Here my HeaderView.swift

import SwiftUI

struct HeaderView: View {
    var body: some View {
        NavigationView {
            Text("ttt").navigationBarItems(leading:
                NavigationLink(destination: GarageView()) {
                    Text("ey")
                },
                trailing:
                Button(action: {}) {
                    Text("ee")
                }
            )
        }
        .accentColor(.green)
        
    
    }
}

struct HeaderView_Previews: PreviewProvider {
    static var previews: some View {
        HeaderView()
            .previewLayout(.fixed(width: 375, height: 300)) //375 80
    }
}

and my contentView.swift :

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack{
            // Top Stack
            HeaderView()
            // Card
            ZStack {
                ForEach(Card.data.reversed()) { card in
                    CardView(card: card).padding(10)
                }
            }.zIndex(1.0)
            // Bottom Stack
            FooterView()
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

but the result is : I don't know why the header is big like this then i click on the button "ey" -> as you can see the new page is the half of my screen I would like my new page take the entire screen...

Do you have an idea ? Thank you.

8diamond
  • 1
  • 1
  • `navigationBarItems` is being deprecated use `.toolbar` – lorem ipsum Apr 20 '21 at 11:54
  • Without a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) it is impossible to help you troubleshoot. You are only showing part of your code. Where does the bottom part come from? – lorem ipsum Apr 20 '21 at 11:58
  • @loremipsum Thank you for you answer, I edited the code, is it enough ? – 8diamond Apr 20 '21 at 12:30
  • It is not a minimum reproducible example but with what you have shown I can tell you that the "issue" is in the `ContentView` the `HeaderView` is a header not an entire `View`/page/screen it is 1/3 when you change the `body` of the header the `ZStack` and the `Footer` still remain. The `NavigationView` should be at the outer most point put it above your `VStack` in the `ContentView` and alter the navigation buttons with `.toolbar` – lorem ipsum Apr 20 '21 at 12:37
  • Oh it's working ! (the navigation) but i don't use .toolbar for the moment. Thank you a lot ! I will try to manage with .toolbar ! – 8diamond Apr 20 '21 at 13:10

0 Answers0