我在玩 SwiftUI 并希望能够在点击按钮时返回上一个视图,就像我们popViewController
在UINavigationController
. 到目前为止有提供的方法吗?
我也尝试过NavigationDestinationLink
这样做但没有成功。
struct AView: View {
var body: some View {
NavigationView {
NavigationButton(destination: BView()) {
Text("Go to B")
}
}
}
}
struct BView: View {
var body: some View {
Button(action: {
// Trying to go back to the previous view
// previously: navigationController.popViewController(animated: true)
}) {
Text("Come back to A")
}
}
}