![](/img/trans.png)
[英]iOS How to set a Sidebar Menu programmatically in the AppDelegate?
[英]Set App Entry point programmatically in AppDelegate
在我的appdelegate中,我想检查globUs.hasName
。 如果是的话,我希望应用程序的Entry Point
成为我的main
故事板。 如果不是,我希望应用程序的Entry Point
成为我的新newUser
故事板。 如何设置应用的入口点? 如果我不能,实现此功能的最有效方法是什么?
考虑没有入口点。 然后,在appDelegate中,测试您的变量并相应地选择适当的故事板。 然后从该故事板显示视图控制器。
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
}
尝试
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()
或者在故事板中尝试手动segue。 要执行手动segue,您必须首先在storyboard中定义带有标识符的segue,然后在视图控制器中调用performSegue(withIdentifier:sender:)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.