Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI NavigationLink Button is gray and untouchable

I can not get a NavigationLink in SwiftUI. The button is visible, but unfortunately this is gray and can not be clicked.

Here is the code:

import SwiftUI
import Combine

struct ContentView: View {
    var body: some View {
        NavigationView{
            NavigationLink(destination: Text("Detail for Test")) {
                    Text("Test")
            }.navigationBarTitle("Select a user")
        }
    }
}

Does anyone know the problem?

like image 757
CodierGott Avatar asked Aug 20 '19 09:08

CodierGott


1 Answers

It seems the problem is related to the fact that you have added the NavigationLink inside the NavigationView without defining a layout

In fact, if you add a VStack, everything works correctly

struct ContentView: View {
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: Destination()) {
                        Text("Test")
                }
            }.navigationBarTitle("Select a user")
        }
    }
}

struct Destination: View {
    var body: some View {
        Text("Ok")
    }
}
like image 182
Giuseppe Sapienza Avatar answered Nov 05 '22 06:11

Giuseppe Sapienza