在 UITabBar 中启动故事板视图
Start a storyboard view in UITabBar
我正在尝试以编程方式在不同故事板文件的 UITabBarController 中启动 UIView。
在WelcomeVC.swift
,它没有UITabBar,住在Main.storyboard
。单击 UIButton 时它调用 UITabBar ViewController
@objc func startMatching(sender: UITapGestureRecognizer){
let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: nil)
let pdv = storyBoard.instantiateViewController(withIdentifier: "AVC") as! AVC
self.present(pdv, animated: true, completion: nil)
}
在Test.storyboard
中,它包含1个UITabBarController和2个视图控制器:AVC
和BVC
。如果我们对它们调用 present() ,它们都会按预期运行,但 UITabBar 不会出现。
如何显示选项卡控制器?
你必须展示 UITabBarViewController
,给它一个故事板标识符并展示它,而不是直接展示 AVC
let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: nil)
let pdv = storyBoard.instantiateViewController(withIdentifier: "TabBarViewController") as! UITabBarViewController
self.present(pdv, animated: true, completion: nil)
我正在尝试以编程方式在不同故事板文件的 UITabBarController 中启动 UIView。
在WelcomeVC.swift
,它没有UITabBar,住在Main.storyboard
。单击 UIButton 时它调用 UITabBar ViewController
@objc func startMatching(sender: UITapGestureRecognizer){
let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: nil)
let pdv = storyBoard.instantiateViewController(withIdentifier: "AVC") as! AVC
self.present(pdv, animated: true, completion: nil)
}
在Test.storyboard
中,它包含1个UITabBarController和2个视图控制器:AVC
和BVC
。如果我们对它们调用 present() ,它们都会按预期运行,但 UITabBar 不会出现。
如何显示选项卡控制器?
你必须展示 UITabBarViewController
,给它一个故事板标识符并展示它,而不是直接展示 AVC
let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: nil)
let pdv = storyBoard.instantiateViewController(withIdentifier: "TabBarViewController") as! UITabBarViewController
self.present(pdv, animated: true, completion: nil)