Swift Multiple Storyboard - How to access specific one
If you want to access other storyboards you need to give that name.
self.storyboard
will always point to your default storyboard. Instead do this :
let VC = UIStoryboard(name: "VCStoryBoardName", bundle: nil).instantiateViewController(withIdentifier: "InstructionScreenController") as! VC
Multiple storyboards: how small should they be?
Using storyboards has it's benefits, and if you want to keep using storyboards there is no reason you should be worried about performance impact of having many storyboards even a storyboard for each ViewController
named after the ViewController
.
Keep in mind that big storyboards take ages to load in the Xcode preview because it renders the whole storyboard file; however, when loading a screen in the app, it would not be loading the whole file just parsing the correct view controller and render only that. Knowing that, you should not see any performance problems from a bigger storyboard in your app.
The general practice shows that it's not good for you as developer to use big storyboards due to merge conflicts, especially if multiple developers are working on the same storyboard file.
If your layout is simple enough it might be worth doing everything in code.
How do I effectively use multiple Storyboards for 100+ view controllers?
Break up your view controllers by functional areas, creating a dedicated storyboard for each (or even more than one). You can then link them together using storyboard references if, for instance, you are worried you might lose the big picture view.
You can even do this storyboard refactoring afterwards by using the handy Extract Storyboard Xcode menu option (i.e., select a VCs subset and then click menu Editor > Extract Storyboard).
Of course, assuming you really need that many view controllers to begin with ;-)
UITabBarController with multiple storyboards
If your target is iOS 9 and above, you should create storyboard references for the view controllers you want to include in another storyboard. Here's how it works:
- Create a second storyboard, move the desired view controller into it and give it a Storyboard ID under the Identity inspector.
- Go to your first storyboard and search for Storyboard Reference in the Object library.
- Drag it into your storyboard and create a "view controllers" relationship with the tab bar controller just like you would with a view controller.
- Under the Storyboard Reference's Attribute inspector, change your settings accordingly. For Referenced ID, use the view controller's ID on the second view controller.
Connecting Multiple Storyboards in Swift
When your app needs to move to a new controller that's in a different storyboard, you have to instantiate the new storyboard, then instantiate the initial view controller there.
let sb = UIStoryboard(name: "SomeStoryboardName", bundle: nil)
let vc2 = sb.instantiateInitialViewController() as UIViewController // or whatever the class is of that initial vc
Related Topics
How to Dismiss Viewcontroller in Swift
Facebook Sdk 3.1 - Error Validating Access Token
How to Use Iboutletcollection to Connect Multiple Uiimageviews to the Same Outlet
Iphone: Hide Uitableview Search Bar by Default
Failed to Read Values in Cfprefsplistsource iOS 10
How to Use Avcapturephotooutput
Failed to Obtain a Cell from Its Datasource
Objective C - Assign, Copy, Retain
How to Get Uikeyboard Size with iOS
Example of Nsattributedstring with Two Different Font Sizes
How to Play a Sound Using Swift
Xcode Nsmanagedobject Subclass Contains Optionals When They Are Marked as Non-Optional
Uitextview That Expands to Text Using Auto Layout
Check If a Uiscrollview Reached the Top or Bottom
How to Use Nslocalizedstring Function with Variables in Swift
Cannot Change Search Bar Background Color
How to Create a Centered Uicollectionview Like in Spotify's Player