1

As you can see below, the notificationsVC is a part of the TabBarController which is embedded in a navigationContoller(lets call it first nC). Then theres a segue from notificationsVC to the second navigationController which will show the messagesVC.

There's a back button in messagesVC which when pressed should go back to notificationsVC

func backbutton() {        
    navigationController?.popViewControllerAnimated(true)         
}

Now this is obviously not working because the navigationController will get the nearest NC and pop the VC in its stack but it won't let me go back to the notificationsVC.

Any other alternative?, although I've tried this with no success as well.

self.dismissViewControllerAnimated(true, completion: nil);

enter image description here

More detailed view enter image description here

Also I'm using the JSQMessagesViewController library to show the messages in messagesVC which shouldn't matter but still worth mentioning. Thanks for your time!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • `navigationController?.navigationController?.popViewControllerAnimated(true)` Pop view from NavigationController of NavigationController. – Dipen Panchasara Aug 25 '16 at 11:55

3 Answers3

0

Try : -

let nVC = self.navigationController?.tabBarController?.navigationController?.storyboard?.instantiateViewControllerWithIdentifier("NotificationStoryboardVC_ID") as! NotificationVC

navigationController?.tabBarController?.navigationController?.pushViewController(nVC, animated: true)
Dravidian
  • 9,945
  • 3
  • 34
  • 74
0

You can access first NavigationViewController by asking it from TabBarViewController like in code below:

tabBarController?.navigationController?.popViewControllerAnimated(true)

Also asking navigation controller from you second navigation controller should work:

navigationController?.navigationController?.popViewControllerAnimated(true)
lazarev
  • 839
  • 10
  • 25
0

Your Navigation controller has only one VC i.e MessagesVc. So when you pop it,there is no other VC in the Navigation Controller's stack which can be presented. Your NotificationsVC is not in the Navigation controller's stack.

So I suggest you to do like this on back button click:

tabBarController?.selectedIndex = Index_Of_NotificationsVC

Vishal Sonawane
  • 2,637
  • 2
  • 16
  • 21