Reputation: 5172
I have app, where is Segmented Control inside of my Navigation Bar. Under navigation bar I have 3 containers. In these containers I have Table View Controllers. If you tap on segmented control, one TVC appear and others disappear (container1.hidden = true and so on).
Problem is when I press "save" button which is also in navigation controller - button doesn't trigger "virtual push of back button".
I used following code which works in my other projects (its in button's action which is in VC that contains all container views) but not this time:
if let navController = self.navigationController {
navController.popViewControllerAnimated(true)
}
UPDATE: Thanks to @ Alexey Bondarchuk I solved it. Comments may be confusing so I just recap problem and solution.
Originally, I had ViewController. To this controller I embed in Navigation Controller. To this Navigation Controller I connected segues. And that was mistake. So I deleted this embed in navigation controller, made (show) segues directly to my View Controller (which is on screenshot). This automatically created navigation bar and last thing I did was that I put navigation item in it so now my code pop right navigationController. Hope that it's understandable.
Upvotes: 1
Views: 341
Reputation: 2022
I have couple ideas:
Your navigationController equal to 'nil' and .popViewControllerAnimated
will never invoked. This may happen if you are using UITabBarController. In this case try to use self.tabBarController?.navigationController
instead of self.navigationController
.
Your controller presented 'Modally'. In this case you can try to invoke navController.dismissViewControllerAnimated
instead of navController.popViewControllerAnimated
Upvotes: 1