我当时正在使用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")
}
}
}
Run Code Online (Sandbox Code Playgroud)