如何在一个VStack中添加两个NavigationLink

时间:2020-06-27 08:22:09

标签: swiftui

我试图在一个VStack中添加两个NavigationLink,但它为我报告了一个未知错误。

struct LoginView: View {   
    @State private var selector = ""

    var body: some View {
        NavigationView {
            VStack(spacing: 30) { // error `Unable to infer complex closure return type; add explicit type to disambiguate`
                NavigationLink(destination: OneView(), tag: "one",
                               selection: $selector) { EmptyView() }
                
                NavigationLink(destination: TwoView(), tag: "two",
                               selection: $selector) { EmptyView() }
                
                Button("change to view") {
                    self.selector = "one"
                }
            }
            .navigationBarTitle("Test Navigation")
        }
    }
}

1 个答案:

答案 0 :(得分:1)

按签名选择应该是可选的,所以这里是解决方法

struct LoginView: View {
    @State private var selector: String? = ""     // << here

    // ... other your code