我从故事板加载了3个视图控制器:
controller1 = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
controller2 = storyboard.instantiateViewController(withIdentifier: "ModelController") as! ModelController
controller3 = storyboard.instantiateViewController(withIdentifier: "BuyController") as! BuyViewController
我想创建并将这3个控制器加载到带有3个按钮的底部导航栏中。
以编程方式。
我只用简单的几行代码就可以做到这一点?
答案 0 :(得分:0)
我为你做了一个示例项目
检查 - https://drive.google.com/open?id=1M12Nv4PLNUePSJFHf7w8b08M2_mWcUEC
一些裁判代码
我的三个VC对象
private lazy var ThirdObject: VC3 =
{
// Instantiate View Controller
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "VC3") as! VC3
// Add View Controller as Child View Controller
self.addChildViewController(viewController)
return viewController
}()
private lazy var FirstObject: VC1 =
{
// Instantiate View Controller
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "VC1") as! VC1
// Add View Controller as Child View Controller
self.addChildViewController(viewController)
return viewController
}()
private lazy var SecondObject: VC2 =
{
// Instantiate View Controller
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "VC2") as! VC2
// Add View Controller as Child View Controller
self.addChildViewController(viewController)
return viewController
}()
故事板视图
模拟器屏幕截图
ScreenShot 1 - 未添加任何对象时
ScreenShot 2 - 点击任何按钮时
我点击了第二个所以显示为
注意:我使用了带有三个按钮的工具栏您可以通过在导航栏中添加按钮,显示方法如何操作来做同样的事情,依赖于您想要使用导航控制器或工具栏在屏幕底部