How do I programmatically set the InitialViewController
for a Storyboard? I want to open my storyboard to a different view depending on some condition which may vary from launch to launch.
Ios – Programmatically set the initial view controller using Storyboards
iosobjective cswiftuistoryboarduiviewcontroller
Related Topic
- Objective-c – How to create a basic UIButton programmatically
- Ios – Loaded nib but the ‘view’ outlet was not set
- Ios – Passing data between view controllers
- Ios – How to animate constraint changes
- Ios – Access Container View Controller from Parent iOS
- Ios – Best practices for Storyboard login screen, handling clearing of data upon logout
- C# – Permissions problem when starting .NET app from .NET service as a different user
Best Answer
How to without a dummy initial view controller
Ensure all initial view controllers have a Storyboard ID.
In the storyboard, uncheck the "Is initial View Controller" attribute from the first view controller.
If you run your app at this point you'll read:
And you'll notice that your window property in the app delegate is now nil.
In the app's setting, go to your target and the
Info
tab. There clear the value ofMain storyboard file base name
. On theGeneral
tab, clear the value forMain Interface
. This will remove the warning.Create the window and desired initial view controller in the app delegate's
application:didFinishLaunchingWithOptions:
method: