Thursday, October 29, 2026
HomeiOS Developmentios - pop to rootController onDisappear from SwiftUI view

ios – pop to rootController onDisappear from SwiftUI view

[ad_1]

I’ve a two ViewControllers A and B and a SwiftUI view, navigating from “A” controller to SwiftUIview inside this carried out NavigationLink to navigate -> “B” controller. Attempting to pop again to Controller “A” from “B” skipping SwiftUI in between

under resolution will not be working

.onDisappear tried one thing like this presentationMode.wrappedValue.dismiss()

On A ViewController

func integrateSwiftUIView() {
        
        let hostingController = UIHostingController(rootView: swiftUIView)

        addChild(hostingController)
        view.addSubview(hostingController.view)

        hostingController.view.translatesAutoresizingMaskIntoConstraints = false
        let constraints = [
            hostingController.view.topAnchor.constraint(equalTo: view.topAnchor),
            hostingController.view.leftAnchor.constraint(equalTo: view.leftAnchor),
            view.bottomAnchor.constraint(equalTo: hostingController.view.bottomAnchor),
            view.rightAnchor.constraint(equalTo: hostingController.view.rightAnchor)
        ]

        NSLayoutConstraint.activate(constraints)

        hostingController.didMove(toParent: self)
    }

On integrateSwiftUIView utilizing UIViewControllerRepresentable to succeed in BViewController

                NavigationLink(isActive: $isPresented) {
                    LaunchBViewController()
                    }) {
                }
  1. Pop again on to AViewController from BViewController
  2. Dismiss SwiftUIView

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments