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.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Enum with associated value conforming to CaseItera
You can set
initial view controller
using Interface Builder as well as programmatically.Below is approach used for programmatically.
Objective-C :
Swift :
I created a routing class to handle dynamic navigation and keep clean AppDelegate class, I hope it will help other too.
And in your AppDelegate call this
I don't think it's possible. Instead you can have one initial controller which will have segues to different view controllers. On startup, you can decide which segue to perform programmatically.
Swift 4, Xcode 9
in file AppDelegate.swift
You can programmatically set the key window's rootViewController in
(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
for example:
In
AppDelegate.swift
you can add the following code:Of course, you need to implement your logic, based on which criteria you'll choose an appropriate view controller.
Also, don't forget to add an identity (select storyboard -> Controller Scene -> Show the identity inspector -> assign StorboardID).