从 Appdelegate 导航时标签栏和导航栏消失
Tab bar and Navigation bar disappeared when navigate from Appdelegate
我使用故事板。当我尝试从 AppDelegate 导航到另一个视图时,该视图中的选项卡栏和导航栏消失了
这是代码
//Some conditions here
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let homeView = storyBoard.instantiateViewController(withIdentifier: "HomeViewController")
self.window?.rootViewController?.present(homeView, animated: true, completion: nil)
您只是将 viewcontroller 加载到根视图。这就是为什么您看不到标签栏或导航栏的原因。您需要出示 Tabbar 或导航控制器才能看到它。
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let homeView = storyBoard.instantiateViewController(withIdentifier: "HomeViewController")
self.window?.rootViewController = UINavigationController(rootViewController: homeView)
使用此代码,它应该适合您
Select ViewController 来自故事板。
转到编辑器并嵌入导航控制器或标签栏控制器
将情节提要 ID 提供给您的导航控制器或标签栏控制器
将导航控制器或标签栏控制器分配给 AppDelegate
的根 Viewcontroller。
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let Root_Vc = storyBoard.instantiateViewController(withIdentifier: "RootVc")
self.window?.rootViewController?.present(Root_Vc, animated: true, completion: nil)
我使用故事板。当我尝试从 AppDelegate 导航到另一个视图时,该视图中的选项卡栏和导航栏消失了
这是代码
//Some conditions here
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let homeView = storyBoard.instantiateViewController(withIdentifier: "HomeViewController")
self.window?.rootViewController?.present(homeView, animated: true, completion: nil)
您只是将 viewcontroller 加载到根视图。这就是为什么您看不到标签栏或导航栏的原因。您需要出示 Tabbar 或导航控制器才能看到它。
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let homeView = storyBoard.instantiateViewController(withIdentifier: "HomeViewController")
self.window?.rootViewController = UINavigationController(rootViewController: homeView)
使用此代码,它应该适合您
Select ViewController 来自故事板。
转到编辑器并嵌入导航控制器或标签栏控制器
将情节提要 ID 提供给您的导航控制器或标签栏控制器
将导航控制器或标签栏控制器分配给 AppDelegate
的根 Viewcontroller。
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let Root_Vc = storyBoard.instantiateViewController(withIdentifier: "RootVc")
self.window?.rootViewController?.present(Root_Vc, animated: true, completion: nil)