I have storyboard with these flow. I am using SWRevealViewController to navigate to each navigation controller.
- Navigation Controller 1 --> View Controller Initial (Home) --> View Controller Target
- Navigation Controller 2 --> View Controller X --> View Controller Y --> View Controller Target
- Navigation Controller 3 --> View Controller M --> View Controller Target
From View Controller Target on each flow, I want to override its back button so it could back to View Controller Initial (Home) and release its object on memory.
Is there any possible way to do this? Any help would be appreciated. Thank you.
Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.
NavController manages app navigation within a NavHost . Apps will generally obtain a controller directly from a host, or by using one of the utility methods on the Navigation class rather than create a controller directly. Navigation flows and destinations are determined by the navigation graph owned by the controller.
First you need to replace your back button with custom Back BarButton with it selector.
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .Done, target: self, action: #selector(self.backToInitial(_:)))
func backToInitial(sender: AnyObject) {
self.navigationController?.popToRootViewControllerAnimated(true)
}
If you are running swift 3.0
then selector
syntax is like this.
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .Done, target: self, action: #selector(self.backToInitial(sender:)))
Edit: For SWRevealViewController
try like this.
let revealController = self.revealViewController;
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("InitialViewController") as! InitialViewController
let navigationController = UINavigationController(rootViewController: vc)
revealController.pushFrontViewController(navigationController, animated:true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With