Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Skip Over Previous View When Back Button Pressed

I have the navigation as:

List of Friends with messages Controller (click compose) -> List of friends to select chatting (select friend) -> Show chat with friend

At present, if within Show chat with friend, and the user selects back, it takes them to the List of friends to select chatting controller. I wish to skip over this controller and, upon back selection, navigate to List of Friends with messages Controller

Note: the List of Friends with messages Controller is an embedded within a tab.

I have attempted using: self.navigationController?.viewControllers.removeLast(), within the segue between the List of friends to select chatting to remove it from the stack. But then after the navigating to Show chat with friend, the back button disappears...

How can I allow the navigation I am describing?

like image 675
Sauron Avatar asked Jun 05 '16 00:06

Sauron


1 Answers

If your goal is to skip second UIViewControllerand pop back to first UIViewController from third UIViewController. Try the following code:

// This count will return how many view controllers are there in navigation stack
let controllersInNavigationCount = self.navigationController?.viewControllers.count

// This will pop to first UIViewController skipping second UIViewController
self.navigationController?.popToViewController(self.navigationController?.viewControllers[controllersInNavigationCount!-2] as! FirstViewController, animated: true)
like image 116
Ashish Verma Avatar answered Nov 15 '22 05:11

Ashish Verma