UIStoryboard: What's the Correct Way to Get the Active Storyboard?

后端 未结 4 2020
无人及你
无人及你 2020-12-13 03:56

I am currently furiously digging through all the docs, and haven\'t quite found what I\'m looking for. I suspect it is a real d\'oh! answer.

I simply need to find th

4条回答
  •  悲哀的现实
    2020-12-13 04:33

    In case you want to get the active storyboard for a viewController, there's a storyboard property. This is how I solved it, instead of making a new instance:

    LoginViewController *vc = [navController.storyboard instantiateViewControllerWithIdentifier:@"firstLaunch"];
    [navController presentModalViewController:vc animated:YES];
    

    In Swift you'd call:

    let loginViewController = navigationController?.storyboard?.instantiateViewController(withIdentifier: "firstLaunch") as! LoginViewController
    navigationController?.present(loginViewController, animated: true, completion: nil)
    

    You could also be a lot safer by using guards against the navigation controller and the storyboard. I've used as! so as to guarantee that you're getting a LoginController.

提交回复
热议问题