我有一个带有信息卡片和一个列表的NavigationView,我想点击该信息并转到另一个视图,或者您可以点击一个列表项,以查看有关该项目的更多信息。 因此,如果我将'onTapGesture'修饰符赋予名片视图,则它的确会打印“ onTap已按下”,但我无法弄清楚如何使它开始另一个视图
var body: some View {
NavigationView {
VStack {
TopResultsCard(games: self.games)
.padding(.top, 10)
.onTapGesture({
print("onTap tapped")
})
ResultsListItem(games: self.games)
}.navigationBarTitle("", displayMode: .inline)
.navigationBarItems(trailing:
Button(action: {
self.showNewResult.toggle()
}) {
Image(systemName: "plus.circle")
Text("Add result")
}
.sheet(isPresented: $showNewResult) {AddResultView(games: self.games)}
.font(.caption))
}
}
答案 0 :(得分:1)
这是可行的方法。使用目标视图代替下面的演示Text("Next view here")
。
@State private var isActive = false
var body: some View {
NavigationView {
VStack {
TopResultsCard(games: self.games)
.padding(.top, 10)
.onTapGesture { self.isActive.toggle() }
.background(NavigationLink(destination:
Text("Next view here"), isActive: $isActive) { EmptyView() })
ResultsListItem(games: self.games)
}.navigationBarTitle("", displayMode: .inline)
.navigationBarItems(trailing:
Button(action: {
self.showNewResult.toggle()
}) {
Image(systemName: "plus.circle")
Text("Add result")
}
.sheet(isPresented: $showNewResult) {AddResultView(games: self.games)}
.font(.caption))
}
}