0

I have managed to open a view controller from app delegate when clicked on push notification from viewcontroller with didReceive method. My issue is managing the hierarchy . Consider I have View A, B and C such that I will get to see View C in these steps: View A -> View B -> View C. But when I click on push notification it takes me to View C so when i click on back button of View C it should have View B and View A in the same stack order. Is it possible to do so?

Edit: This is my code if it helps

I want BaseVc > secondBaseVc > LogbookVc > DetailVc

        if let info = userInfo as? [String:Any]{
        let id = info["id"] as? String ?? ""


        let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        let BaseVc = storyBoard.instantiateViewController(withIdentifier: "BaseViewController") as! BaseViewController
        let secondStoryboard : UIStoryboard = UIStoryboard(name: "Second Storyboard", bundle: nil)

        let secondBaseVc : BaseController = secondStoryboard.instantiateViewController(withIdentifier: "secondBaseVc") as! secondBaseVc
        let LogbookVc : LogbookVc = secondStoryboard.instantiateViewController(withIdentifier: "LogbookVc") as! LogbookVc
        let DetailVc: DetailVc = secondStoryboard.instantiateViewController(withIdentifier: "DetailVc") as! DetailVc

    }

How should i connect them to show DetailVc but get them in order so as when i click back button i should have Logbook < secondBaseVc < Base Vc

Rushikesh
  • 41
  • 1
  • 4
  • In this case you can manually navigate with animation off – Dharmesh Kheni Jul 25 '18 at 14:40
  • Yes you can do this on clicking the push notification navigate user to View C. After presenting View C create View A and View B and insert into navigationController's viewControllers array property manually, so the final viewControllers array property should have in the order A-B-C. – vivekDas Jul 25 '18 at 16:25
  • where is your code for pushing to navigationController?, you have initiated the instances for the Classes but not pushed. Please add that too – Bhavin Kansagara Jul 26 '18 at 09:39

1 Answers1

0

Not actually, if you are not having those viewControllers A and B in stack, then you can not have something to pop to previous viewController.

In my opinion, what you can do is: You have to handle this by your self, like, when notification received. You have to first push A, then B and then C, by putting animation: false, so it will not produce the effect of transition.

.navigationController?.pushViewController(objA, animated: false) .navigationController?.pushViewController(objB, animated: false) .navigationController?.pushViewController(objC, animated: false)

EDIT

        let navigationController = UINavigationController(rootViewController: baseVc)
        navigationController.pushViewController(logbookVc, animated: false)
        navigationController.pushViewController(detailVc, animated: false)

        self.window?.rootViewController = navigationController
        self.window?.makeKeyAndVisible()

IMPORTANT NOTE:

Create your object name with camelCase for proper readability. e.g let BaseVc should be let baseVc and same for the logbookVc and detailVc

Try and share the results.

Hope it helps.

Bhavin Kansagara
  • 2,866
  • 1
  • 16
  • 20
  • Ok . This was useful but still it didnt take me past the B view i.e. to C. Can it be more specific? – Rushikesh Jul 25 '18 at 15:20
  • can you share some codes to get the better idea about the problem you are facing in achieving it.? It should work as suggested because, navigationController is holding the stack of all the viewControllers previously pushed and when you pop, it will show you previous one. – Bhavin Kansagara Jul 25 '18 at 15:26