本文介绍了SwiftUI如何在点击Button时推送到下一个屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用NavigationButton(按入)导航到下一个屏幕,也可以与PresentationButton(呈现)一起显示,但是我想在点击Buttton()时进行推送
I can navigate to next screen by using NavigationButton (push) or present with PresentationButton (present) but i want to push when i tap on Buttton()
Button(action: {
// move to next screen
}) {
Text("See More")
}
有办法吗?
推荐答案
您可以使用NavigationLink
You can do using NavigationLink
struct MasterView: View {
@State var selection: Int? = nil
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: DetailsView(), tag: 1, selection: $selection) {
Button("Press me") {
self.selection = 1
}
}
}
}
}
}
struct DetailsView: View {
@Environment(\.presentationMode) var presentation
var body: some View {
Group {
Button("Go Back") {
self.presentation.wrappedValue.dismiss()
}
}
}
}
这篇关于SwiftUI如何在点击Button时推送到下一个屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!