Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationLink is grayed out and does not perform any action [duplicate]

Tags:

swift

swiftui

import SwiftUI

struct ContentView: View {    
    var body: some View {
        NavigationLink(destination: DetailView()) {
            Text("Show Details")
        }
    }
}

struct DetailView: View {
    var body: some View {
        Text("Detailed")
    }
}

This code gives me a gray text (or button) saying 'Show Details' which is not touchable and does not perform the intended action (navigating to DetailView). Was there a change in the API or is it a bug?

I am using the newest versions of Xcode (Xcode 11 Beta 6 and macOS Catalina 10.15 Beta 6)

like image 775
Prydwen Avatar asked Aug 25 '19 10:08

Prydwen


1 Answers

Your ContentView should have a NavigationView for NavigationLink to work, and be enclosed in some 'element', here a VStack

struct ContentView: View {    
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: DetailView()) {
                     Text("Show Details")
                }
            }
        }
    }
}

Hope this helps!

like image 84
fa65 Avatar answered Nov 15 '22 11:11

fa65