Automatically set application entry point in AppDelegate

In my appdelegate I want to check if there is globUs.hasName. If so, I want the Entry Pointapplication to be my storyboard main. If this is not the case, I want the Entry Pointapplication to be my storyboard newUser. How to set the entry point to the application? If I can’t, then what is the most efficient way to implement this functionality?

+4
source share
2 answers

Suppose you have no entry point. Then, in appDelegate, check your variable and select the appropriate storyboard accordingly. Then display the view controller from this 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
}
+3
source

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 selection in the storyboard. To perform manual segregation, you must first define a segue with an identifier in the storyboard, and then call it performSegue(withIdentifier:sender:)in the view manager.

0
source

Source: https://habr.com/ru/post/1669436/


All Articles