0

Je rencontre ce problème lorsque j'ouvre un nouveau View Controller par programmation.La barre d'onglets n'apparaît pas dans View Controller à l'intérieur du contrôleur de navigation

let controller = self.storyboard?.instantiateViewController(withIdentifier: "overViewScreen") as! OverviewViewController 
controller.user = self.userObject 
let navigationController = UINavigationController(rootViewController: controller) 
self.present(navigationController, animated: true, completion: nil) 

La structure de mon projet: storyboard

Sur mon storyboard la barre d'onglets est affichée sur le contrôleur de vue (avec la table à droite), mais quand je lance l'application, il ressemble à ceci : enter image description here

J'espère que vous les gars peuvent me aider! Merci.

Répondre

0

Vous présentez NavigationController sans contrôleur de barre d'onglets. Vous devez présenter TabBarController.

Donnez votre identifiant de TabBarController et les instancier comme vous l'avez fait avec le contrôleur

Code de commentaire:

let tabVC = UIStoryboard(name: "NameOfYourStoryboard", bundle: Bundle.main).instantiateInitialViewController() as! UITabBarController 

let navVc = tabVC.viewControllers.first as! UINavigationController 

let vc = navVc.viewControllers.first as! OverviewViewController 
vc.incorrectAuthorization = SettingsAuthorizationMethod.fingerprint 
vc.user = self.userObject 

present(navController, animated: true, completion: nil) 
+0

Voulez-vous dire quelque chose comme ça? let tabBarController = self.storyboard? .instantiateViewController (withIdentifier: "TabBarController") self.present (tabBarController !, animé: true, complétion: nil) –

+0

Ou quelque chose comme: let tabVC = UIStoryboard (name: "NameOfYourStoryboard", bundle: Bundle.main) .instantiateInitialViewController() as! UITabBarController laisser navVc = tabVC.viewControllers.first comme! UINavigationController let vc = navVc.viewControllers.first comme! LoginViewController vc.incorrectAuthorization = SettingsAuthorizationMethod.fingerprint vc.user = self.userObject présent (NavController, animé: true, achèvement: néant) –

+0

Alors maintenant, je dois: laisser tabBarController = self.storyboard .instantiateInitialViewController() comme! UITabBarController laissez navVc = tabBarController.childViewControllers.first as! UINavigationController laissez vc = navVc.childViewControllers.first as! AperçuViewController vc.user = self.userObject self.present (navVc, animé: vrai, achèvement: aucun). Erreur: Impossible de convertir LoginViewController en UITabBarController –

0

Ok, j'ai réussi à le fixer comme celui-ci:

let vc = self.storyboard?.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController 
          vc.user = self.userObject 
          let nvc = UINavigationController(rootViewController: vc) 
          self.present(nvc, animated: true, completion: nil) 

J'ai créé une classe de contrôleur séparée "TabBarController" et ajouté une propriété "user" à cette classe. Dans mon "OverViewController" je peux obtenir la propriété comme suit:

let tabBar: TabBarController = tabBarController as! TabBarController 
    user = tabBar.user 

Merci pour l'aide!