Reputation: 111
I'm using swift in iOS. I have to navigate back to my rootViewController from the current UIViewController by clicking on a button and I am not using UINavigationController.
I have made action on a button in my root rootViewController which triggers the segue and goes from root UIViewController to the next VC by the following code:
performSegue(withIdentifier: "segueSignUp", sender: nil)
I can't find any answers to it without the navigation controller.
Upvotes: 0
Views: 149
Reputation: 1278
If you have a segue and you are presenting modally the next ViewController
you can dismiss it.
@IBAction func buttonClicked(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
But if you are very down in the chain of viewController
has presented few more and want to return to root then you can do a unwindSegue
@IBAction func unwindFromViewController(_ sender: UIStoryboardSegue) {
}
Upvotes: 0
Reputation: 1909
Try this in your button action:
@IBAction func buttonClicked(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
Upvotes: 1
Reputation: 884
You could implement unwind segue. In RootController:
@IBAction func unwindFromViewController(_ sender: UIStoryboardSegue) { }
In nextVC in IB, connect the button to exit button at top of VC window in IB and select unwindFromViewController
Upvotes: 0