简体   繁体   中英

How to navigate from one storyboard to another TabBarController?

I'm trying to create an onboarding page for my Application which view is like this :

入职故事板

The Not Now Button supposed to navigate from this Onboarding Storyboard to ForYou Storyboard which have a storyboard that embed in navigation controller and tab bar controller.

为你故事板

Based on my research, i can use this line of code to make it happened

let barViewControllers = UIStoryboardSegue.init(identifier: "ForYou", source: OnboardingMasterViewController(), destination: ForYouViewController()) as! UITabBarController
let nav = barViewControllers.viewControllers![0] as! UINavigationController
let destinationViewController = nav.topViewController as! ForYouViewController

It build successfully but when i run it on simulator, the apps crash and show this line of error that i never see or learn before. The error is Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

错误信息

I tried to look to google but either i used a wrong keyword or my lack of understanding, i still can't solved this error. Hope one of you can give me a guidance in finding the solution.

Thank you.

I am guessing you have already given an identifier to the Segue that I can see on the Onboarding Storyboard to ForYou Storyboard.

If not, click on that Segue in your storyboard and give its identifier.

Now, on the Not Now button's action you can do the following instead of the code that you have

performSegue(withIdentifier: "your-segue-identifier", sender: nil)

OR

You can directly connect the Segue in the storyboard from your Not Now button to ForYou storyboard, that way you won't need to write any code to achieve this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM