【发布时间】:2020-09-18 10:50:29
【问题描述】:
这是我的 SwiftUI 设置:
我有一个 SwiftUI 视图(称为 MapSearchView),它有一个包含 NavigationLink 的 NavigationView。
var body: some View {
VStack {
NavigationView {
Form {
Section (header: Text("Location")){
NavigationLink (locationString, destination: GooglePlacesViewController(mapTools: $mapTools))
}...
NavigationLink 的目的地是一个 UIViewControllerRepresentable,它包装了一个 GooglePlacesViewController。当我完成 GooglePlaces 搜索(因为我进行了选择或取消了搜索)后,我想以编程方式弹回 MapSearchView。
我尝试在 UIViewControllerRepresentable (GooglePlacesViewController) 中添加以下内容:
@Environment(\.presentationMode) var presentationMode
var popToPrevious : Bool = false {
didSet {
if popToPrevious == true {
self.presentationMode.wrappedValue.dismiss()
}
}
}
并在我的协调器中使用
将 popToPrevious 设置为 trueparent.popToPrevious = true
它确实被调用了,但什么也不做。
我也试过在Coordinator中调用
view.viewController().navigationController.popViewController(animated: true)
(viewController() 是获取任何视图的 viewController 的扩展)
这也无济于事。
想法?
【问题讨论】:
标签: swift swiftui navigationview navigationlink uiviewcontrollerrepresentable