I have 3 View Controllers. The first 2 view controllers are embedded in UINavigationController
, as shown in the screenshot:
The starting point is at View Controller 1's UINavigationController
. Then, I push to View Controller 3. However, I would like it to pop to the root of UINavigationController
containing View Controller 2. How can I change the navigation hierarchy?
p.s. this storyboard is simplified for illustration purpose; they are many view controllers in between View Controller 1, 2 and 3.
I end up changing the entire UINavigationController
hierarchy with the following codes:
// In the View Controller 3's button's `IBAction`:
NSArray *vcs = @[[self.storyboard instantiateViewControllerWithIdentifier:@"NavController1_Identifier"], self];
[self.navigationController setViewControllers:vcs];
[self.navigationController popToRootViewControllerAnimated:YES];
where NavController1_Identifier
is the first UINavigationController
's storyboard identifier.
Seems unwind segue can be used in this case too.