簡體   English   中英

在AppDelegate中以編程方式設置App Entry點

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM