Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch Between Storyboards Using Swift

I have a storyboard that is getting too large in my Xcode project and slowing down my computer. How do I programmatically (or manually using storyboarding) go from one of my views in the current storyboard using a button to advance to a view on the new storyboard?

Semi-new with Xcode so the simpler the better. Thanks!

like image 550
Seth Avatar asked Apr 08 '15 04:04

Seth


People also ask

How do I call a storyboard in Swift?

You need to give your viewcontroller an identifier. You do that by highlighting your view controller and then give it a identifier: You then put your identifier in StoryBoard ID.

Can we use SwiftUI and storyboard together?

The answer is YES! Here we will be discussing a simple way to use SwiftUI into our existing project, which already consists of a storyboard.


1 Answers

You can do it programatically this way:

Swift 3+

let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: "ViewControllerID") as UIViewController present(vc, animated: true, completion: nil) 

Older

let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil) let vc = storyboard.instantiateViewControllerWithIdentifier("nextViewController") as UIViewController presentViewController(vc, animated: true, completion: nil)  

In Sort you can do it like:

presentViewController( UIStoryboard(name: "myStoryboardName", bundle: nil).instantiateViewControllerWithIdentifier("nextViewController") as UIViewController, animated: true, completion: nil) 

And don't forget to give ID to your nextViewController.

For more Info refer THIS.

like image 125
Dharmesh Kheni Avatar answered Sep 28 '22 03:09

Dharmesh Kheni