poptorootviewcontroller and instruct rootviewcontroller to perform some action

447 views Asked by At

I have a navigationcontroller, and under that I have controller A as rootviewcontroller and controller B is linked to A through a default push segue.

What I want to do is to when some action is pressed in B, I will ask the navigation controller to pop to rootviewcontroller, which is A, and apply some popovercontroller(or just another view or another window) on top of A.

Someone suggested me to ask appdelegate to create another window on top of current uiwindow. I think it is possible and I want to know if there is any simpler/more elegant solution for this problem.

a general solution of what I can do will be appreciated and some simple code samples in Swift will be much more appreciated :P

1

There are 1 answers

1
Junchao Gu On BEST ANSWER

I will just provide my own answer here.

According to my own experience, there is no popping segue and therefore we cannot exactly get destination view controller from segue. however, UINavigationController has an attribute viewControllers which basically are all children controllers on the stack.

so before popToRootViewController, just get the VC but calling self.nagivationController.viewControllers[0] and you get the root view controller already