Reputation: 5039
I am using Xib
instead of storyboard and using this code in my AppDelegate
to perform navigation in my project
var nav = UINavigationController()
let FirstVC = HomeScreenVIewController(nibName: "HomeScreenVIewController", bundle: nil) as HomeScreenVIewController
nav = UINavigationController(rootViewController: FirstVC)
nav.navigationBarHidden = true
self.window?.rootViewController = nav
self.window?.makeKeyAndVisible()
nav.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
To navigate from one view to other on button click I am using this code
let NextVc = RegistrationStepOneViewController(nibName: "RegistrationStepOneViewController", bundle: nil) as RegistrationStepOneViewController
appDelegate.nav.pushViewController(NextVc, animated: true)
This navigation will go for all registration process steps. When registration is completed there is a dashboard screen from where user can not navigate back to registration steps(obviously).
Now I want another navigation to start from dashboard and go futher in the application. How can I do that ?
Thanks in advance :-)
Upvotes: 0
Views: 142
Reputation: 27438
You can do something like,
let vc: UIViewController = UIViewController()
let view: UIView = UIView(frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height))
vc.view = view
vc.view.backgroundColor = UIColor.orangeColor()
let arr: [UIViewController] = [vc as UIViewController]
self.navigationController!.setViewControllers(arr, animated: true)
You can set array of viewcontrollers
to navigation controller. You can add multiple array to that arr and can use same navigation controller.
Upvotes: 0
Reputation: 3235
You can use the setViewControllers: animated: method to replace the current navigation stack with whatever stack you'd like.
self.navigationController?.setViewControllers([yourNewRootVC], animated: true)
The above, for example, would give you a new root controller and would blow up your current nav stack.
Having said that, with the situation you are describing, I would recommend launching the app with the main view controller as the root of your nav VC, then presenting (animated: false) the registration flow over that. Then you just need to dismiss it once registration is complete or not present it at all if registration has already happened. Hope that makes sense!
Upvotes: 1