我有这些流程的故事板。 我正在使用SWRevealViewController导航到每个导航控制器。
- 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从每个流的View Controller Target中 ,我想覆盖它的后退按钮,以便它可以返回到View Controller Initial(Home)并将其对象释放到内存中。
有没有可能的方法来做到这一点? 任何帮助,将不胜感激。 谢谢。
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 TargetFrom 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.
最满意答案
首先你需要用自定义Back BarButton替换你的后退按钮。
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .Done, target: self, action: #selector(self.backToInitial(_:))) func backToInitial(sender: AnyObject) { self.navigationController?.popToRootViewControllerAnimated(true) }如果你正在运行swift 3.0那么selector语法就像这样。
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .Done, target: self, action: #selector(self.backToInitial(sender:)))编辑:对于SWRevealViewController尝试像这样。
let revealController = self.revealViewController; let vc = self.storyboard?.instantiateViewControllerWithIdentifier("InitialViewController") as! InitialViewController let navigationController = UINavigationController(rootViewController: vc) revealController.pushFrontViewController(navigationController, animated:true)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)更多推荐
发布评论