SwiftUI NavigationLink Button is gray and untouchable

 ̄綄美尐妖づ 提交于 2019-12-02 03:28:35

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")
    }
}

The error is related to a missing view in your NavigationLink statement.

...

NavigationLink(destination: NeedsAView()) {
    Text("Test")
}.navigationBarTitle("Select a user")

...

struct NeedsAView: View {
    var body: some View {
        Text("Hello Destination")
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!