ios - How can I change the initial ViewController in LaunchScreen with Swift? -
i want check whether user logged in or not, if user logged in, bring him main screen, or show welcome screen.
you can't in launch screen, can achieve same in appdelegate's method didfinishlauchingwithoption
, there can check if user logged in or not , set root view controller , don't set initialviewcontroller in storyboard. should
nsstring *identifier = isloggedin ? @"identifierforvc1" : @"identifierforvc2"; uistoryboard *storyboard = [uistoryboard storyboardwithname:@"main" bundle:nil]; uiviewcontroller *vc = [storyboard instantiateviewcontrollerwithidentifier: identifier]; self.window.rootviewcontroller = vc;
code not tested in editor may have swift code should this
let storyboard = uistoryboard(name: "main", bundle: nil) let vc = storyboard.instantiateviewcontrollerwithidentifier(identifier) as! uiviewcontroller self.window?.rootviewcontroller = vc
Comments
Post a Comment