Xcode Navigationlink not working

I have made a navigation bar in "Contentview" linked with each their tabitem to a swift.view file/page.

One of the pages they are linking to are a "dashboard/homepage".

I'm trying to add a button in the "dashboard.swiftview"file to another page/swiftview file called "Oppgaver". I get the button on the page, but its not clickable. What should I do?

This is the code:

import SwiftUI

struct Dashboard: View {   @State var datestring = ""       var body: some View {           NavigationLink (destination: Gj_reoppgave(), label: {         Text("Gå til gjøreoppgaver")           .foregroundColor(.white)           .font(.headline)           .frame(height:55)           .frame(maxWidth: .infinity)           .background(.blue)           .cornerRadius(10)           .multilineTextAlignment(.center)           .padding(30)       })                    } }

struct Dashboard_Previews: PreviewProvider {   static var previews: some View {     Dashboard()   } } }

Answered by SpaceMan in 722038022

It would be clearer if you had embedded your code in a code block.

Accepted Answer

It would be clearer if you had embedded your code in a code block.

import SwiftUI

struct Dashboard: View {
  @State var datestring = ""
   
  var body: some View {
    ZStack {
      LinearGradient (gradient: Gradient(colors: [.blue, .white]), startPoint: .topLeading, endPoint:.bottomTrailing)
      .edgesIgnoringSafeArea(.all)
    VStack {
        
    VStack {
          Text("Hei Håkon 👋")
          .font(.system(size: 32, weight:.medium, design: .default))
          .foregroundColor(.white)
      Text("Dagens dato er \(datestring)")
      .foregroundColor(.white)
       
      .onAppear {
        datestring =
        Date.now.formatted(.dateTime.weekday().day().month())      }


           
    }
         
      VStack {
        Text("🛥️")
        .font(.system(size: 120, weight:.medium, design: .default))
        .foregroundColor(.white)
        .padding(10)
         

      }
     
    VStack {
        Text("Dagens tilstander 🌊")
            .font(.system(size: 25, weight:.medium, design: .default))
            .foregroundColor(.white)
            .padding(15)
       
      }
     
      Spacer()
    }
       
      NavigationLink (destination: Gj_reoppgave(), label: {
        Text("Gå til gjøreoppgaver")
          .foregroundColor(.white)
          .font(.headline)
          .frame(height:55)
          .frame(maxWidth: .infinity)
          .background(.blue)
          .cornerRadius(10)
          .multilineTextAlignment(.center)
          .padding(30)
      })
        
     
    }
}

struct Dashboard_Previews: PreviewProvider {
  static var previews: some View {
    Dashboard()
  }
}
}

I recommend using the init

NavigationLink {
    DestinationView() } label: {
        LabelView() 
}

The version you are using is deprecated in iOS 16.

Why do you have VStacks within a VStack? It seems to me that you could ditch (get rid of) the inner VStacks.

Xcode Navigationlink not working
 
 
Q