skip to Main Content

If I click on the push notification, it takes me to the details page but when I click on the programatically created back button, it takes me back to HomeVC but with the top nav bar gone. Here is my app delegate function where I present the details VC :

 private func gotoDetailsVC(value : String)


      {
            guard let window = UIApplication.shared.connectedScenes.filter({$0.activationState == .foregroundActive 
|| $0.activationState == .background || $0.activationState == .foregroundInactive}).compactMap({$0 as? UIWindowScene}).first?.windows.filter({$0.isKeyWindow}).first
            else { return }

        let storyboard = UIStoryboard(name: "Home", bundle: nil)
        let detailsVC = storyboard.instantiateViewController(identifier: "viewDeviceDataController") as viewDeviceDataController
        detailsVC.deviceID = value
        detailsVC.didComeFromPN = true
        
        
        let navController = UINavigationController(rootViewController: detailsVC)
        navController.modalPresentationStyle = .popover

        // you can assign your vc directly or push it in navigation stack as follows:
        window.rootViewController = navController
        window.makeKeyAndVisible()
    }

And here is my back button on the DetailsVC :

@objc func backAction() {
        
        let storyboard = UIStoryboard.init(name: "Home", bundle: nil)
        let homeVC = storyboard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
        homeVC.modalPresentationStyle = .automatic
        present(homeVC, animated: true, completion: nil)
        
         }

How can I resolve this issue? Please help.

2

Answers


  1. Chosen as BEST ANSWER

    Resolved by navigating to root Navigation Controller.

     @objc func backAction() {
            
            let storyboard = UIStoryboard.init(name: "Home", bundle: nil)
            let homeVC = storyboard.instantiateViewController(withIdentifier: "navControllerHome") as! UINavigationController
            homeVC.modalPresentationStyle = .fullScreen
            present(homeVC, animated: true, completion: nil)
            
             }
    

  2. Usually back action would just return to a previous state, but here it seems you are recreating the view.
    I would not make private func gotoDetailsVC(value : String) replace rootViewController and instead make it be presented by current navigationController then on your back action you would not create a new home but dismiss your detail screen.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search