2

我希望能够点击此表单中的整行以导航到下一个视图;我究竟做错了什么?如果我点击末尾的符号,它只允许我导航。此代码应在您的模拟器中编译和运行。谢谢。

import SwiftUI

struct SwiftUIView: View {
    let selectedTags = ["A", "B", "C"]

    var body: some View {
        NavigationView {
            Form {
                NavigationLink(destination: DetailView()) {
                    ScrollView(.horizontal) {
                        HStack {
                            ForEach(selectedTags, id: \.self) { tag in
                                Text(tag)
                            }
                        }
                    }
                }
            }
        }
    }
}

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

struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        SwiftUIView()
    }
}
4

1 回答 1

1

复制-粘贴-运行

import SwiftUI

struct ContentView: View {
    let selectedTags = ["A", "B", "C"]
    @State var active = false
    var body: some View {
        NavigationView {
            Form {
                NavigationLink( destination: DetailView(), isActive: $active) {
                    ScrollView(.horizontal) {
                        HStack {
                            ForEach(selectedTags, id: \.self) { tag in
                                Text(tag)
                            }
                        }
                    }.onTapGesture {
                        self.active.toggle()
                    }
                }
            }
        }
    }
}

struct DetailView: View {
    var body: some View {
        Text("Welcome")
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
于 2020-03-22T22:49:30.337 回答