[英]Set App Entry point programmatically in AppDelegate
In my appdelegate I want to check if globUs.hasName
. 在我的appdelegate中,我想检查globUs.hasName
。 If it does I want the Entry Point
of the app to be my main
storyboard. 如果是的话,我希望应用程序的Entry Point
成为我的main
故事板。 If it does not I want the Entry Point
of the app to be my newUser
storyboard. 如果不是,我希望应用程序的Entry Point
成为我的新newUser
故事板。 How do I set the entry point of the app? 如何设置应用的入口点? If I can't, what is the most effective way to implement this functionality? 如果我不能,实现此功能的最有效方法是什么?
Consider not having an entry point. 考虑没有入口点。 Then, in appDelegate, test for your variable and choose the appropriate storyboard accordingly. 然后,在appDelegate中,测试您的变量并相应地选择适当的故事板。 Then show the view controller from that storyboard. 然后从该故事板显示视图控制器。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if globUs.hasName {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "FirstMainVC")
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = new
self.window?.makeKeyAndVisible()
}
else {
let storyboard = UIStoryboard(name: "NewUser", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "FirstNewUserVC")
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = welcomeVC
self.window?.makeKeyAndVisible()
}
return true
}
Try 尝试
var sb = UIStoryboard(name: "OneStoryboard", bundle: nil)
/// Load initial view controller
var vc = sb.instantiateInitialViewController()
/// Or load with identifier
var vc = instantiateViewController(withIdentifier: "foobarViewController")
/// Set root window and make key and visible
self.window = UIWindow(frame: UIScreen.mainScreen.bounds)
self.window.rootViewController = vc
self.window.makeKeyAndVisible()
Or try manual segue in storyboard. 或者在故事板中尝试手动segue。 To perform manual segue, you have to first define a segue with identifier in storyboard and then call performSegue(withIdentifier:sender:)
in view controller. 要执行手动segue,您必须首先在storyboard中定义带有标识符的segue,然后在视图控制器中调用performSegue(withIdentifier:sender:)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.